温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

关于元组,元组和列表之间的转换

发布时间:2020-07-31 23:41:29 来源:网络 阅读:584 作者:pengchunboke 栏目:开发技术

注意元组是小括号,而且元祖只有两个功能count和index

>>> t=(1,2,3,4)

>>> dir(t)

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']

>>> 


元祖转换成列表

>>> type(t)

<type 'tuple'>

>>> a=list(t)

>>> type(a)

<type 'list'>


列表转换成元祖

>>> a

[1, 2, 3, 4]

>>> type(a)

<type 'list'>

>>> t=tuple(a)

>>> t

(1, 2, 3, 4)

>>> type(t)

<type 'tuple'>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI