元组
-
>>> t=("milo",30,"male")
-
>>> t[0]
-
'milo'
-
>>> t[1]
-
30
-
>>> t[2]
-
'male'
注意元组只有一个元素时,后面有一个分号,
t1=(2,)
赋值
-
>>> t
-
('milo', 30, 'male')
-
>>> name,age,gender=t
-
>>> name
-
'milo'
-
>>> age
-
30
-
>>> gender
-
'male'
2.列表
列表组成用[]
-
>>> list1=["Simon","David","Clotho","张三"]
-
>>> list2=[1,2,3,4,5]
-
>>> str1="abcd"
-
>>> str2="efgh"
-
>>> str3="ijkl"
-
>>> str4="wxyz"
-
>>> list3=["str1","str2","str3","str4"]
-
>>>list3[0]
-
str1 //跟元组相同
向列表中添加值 list3.append("12345678")
-
>>> list3
-
['abcd', 'efgh', 'ijkl', 'wxyz']
-
>>> list3.append("12345678")
-
>>>list3
-
['abcd', 'efgh', 'ijkl', 'wxyz', '12345678']
删除一个值
list3.remove('12345678')
-
-
>>> list3[3]('wxyz')
-
>>> list3
-
['abcd', 'efgh', 'ijkl', 'wxyz'
重新赋值
阅读(1128) | 评论(0) | 转发(0) |