日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

6.序列!序列!

發布時間:2025/3/21 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 6.序列!序列! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
列表/元組/字符串的共同點: - 都可以通過索引得到每一個元素 - 默認索引從0開始 - 切片方法得到一個范圍內的元素的集合 - 有很多共同的操作符(重復操作符/拼接操作符/成員關系操作符)

list():把可迭代對象轉換為列表

help(list)見下: class list(object)| list() -> new empty list| list(iterable) -> new list initialized from iterable's items| | Methods defined here:| | __add__(...)| x.__add__(y) <==> x+y| | __contains__(...)| x.__contains__(y) <==> y in x| | __delitem__(...)| x.__delitem__(y) <==> del x[y]| | __delslice__(...)| x.__delslice__(i, j) <==> del x[i:j]| | Use of negative indices is not supported.| | __eq__(...)【例】 >>> a = list() >>> a [] >>> >>> b = 'I love fishC' >>> b = list(b) >>> b ['I', ' ', 'l', 'o', 'v', 'e', ' ', 'f', 'i', 's', 'h', 'C'] >>>

tuple:把可迭代對象轉換成元組

help(tuple)見下: class tuple(object)| tuple() -> empty tuple| tuple(iterable) -> tuple initialized from iterable's items| | If the argument is a tuple, the return value is the same object.| | Methods defined here:| | __add__(...)| x.__add__(y) <==> x+y| | __contains__(...)| x.__contains__(y) <==> y in x| | __eq__(...)| x.__eq__(y) <==> x==y| | __ge__(...)| x.__ge__(y) <==> x>=y| | __getattribute__(...)【例】 >>> a = tuple() >>> a () >>> >>> b = 'I love fishC' >>> b = tuple(b) >>> b ('I', ' ', 'l', 'o', 'v', 'e', ' ', 'f', 'i', 's', 'h', 'C') >>>

str:把參數轉換成字符串

help(str)見下: class str(basestring)| str(object='') -> string| | Return a nice string representation of the object.| If the argument is a string, the return value is the same object.| | Method resolution order:| str| basestring| object| | Methods defined here:| | __add__(...)| x.__add__(y) <==> x+y| | __contains__(...)| x.__contains__(y) <==> y in x| | __eq__(...)| x.__eq__(y) <==> x==y【例】 >>> a = 'I love fishC' >>> str(a) 'I love fishC' >>> >>> len(a) #長度 12 >>> max(a) #返回序列或參數集合中的最大值 'v' >>> max(1,1,2,-3,4) #min()最小值 4 >>> tuple = (1,2,3,4,5) >>> max(tuple) 5 >>> min(tuple) 1 注解:使用max/min,必須保證數據類型一致 >>> t1 = (1,2,3,4) >>> sum(t1) #求總和 10 >>> sorted(t1) #排序 [1, 2, 3, 4]reversed #反轉 >>> reversed(t1) <reversed object at 0x7f1c2cb10690> #返回的是一個迭代器對象 >>> list(reversed(t1)) #把迭代器對象轉換成list [4, 3, 2, 1]enumerate >>> enumerate(t1) <enumerate object at 0x7f1c2cb54aa0> #返回的是一個迭代器對象 >>> list(enumerate(t1)) [(0, 1), (1, 2), (2, 3), (3, 4)] #把迭代器對象轉換成listzip >>> t1 = (1,2) >>> t2 = (4,5,6,7,8) >>> zip(t1,t2) [(1, 4), (2, 5)]

總結

以上是生活随笔為你收集整理的6.序列!序列!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。