元组tuple

与列表类似,只是不可变
特点:(),无序

创建元组

#!/usr/bin/env python
# -*- coding:utf-8 -*-
tuple1 = tuple(['a', 'b', 'c', 'd'])
tuple2 = ('a', 'b', 'c', 'd')
print(tuple2)

访问元组元素

#!/usr/bin/env python
# -*- coding:utf-8 -*-
tuple1 = ('a', 'b', 'c', 'd')
print(tuple1[0])
print(tuple1[2])

不能修改!!!!!

想一想:元组有什么用?

results matching ""

    No results matching ""