元组和列表的创建

元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可。

>>> a,b=[2,3]
>>> print(a)
2
>>> b
3
>>> type(a)
<class 'int'>
>>> type(b)
<class 'int'>
>>> a,b=4,5
>>> a
4
>>> b
5
>>> type(a)
<class 'int'>
>>> type(b)
<class 'int'>
>>> a=4,5
>>> a
(4, 5)
>>> type(a)
<class 'tuple'>
>>> b=4,'b'
>>> b
(4, 'b')
>>> type(b)
<class 'tuple'>
>>> a,b=(a,b)
>>> a
(4, 5)
>>> b
(4, 'b')
>>> c,d=(7,8)
>>> c
7
>>> d
8
>>> type(c)
<class 'int'>
>>> type(d)
<class 'int'>
>>> a=(7,8)
>>> a
(7, 8)
>>> type(a)
<class 'tuple'>
>>> a=[7,8]
>>> a
[7, 8]
>>> type(a)
<class 'list'>
>>> 

 

posted @ 2018-06-05 22:28  巨兽~墨菲特  阅读(188)  评论(0编辑  收藏  举报