>>> listTest = ['ha','test','yes'] >>> listTest ['ha', 'test', 'yes']
>>> len(listTest) 3
>>> listTest[0] 'ha' >>> listTest[1] 'test' >>> listTest[3] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: list index out of range >>> listTest[-1] 'yes' >>> listTest[-2] 'test'
>>> listTest.insert(1,'jack') >>> listTest ['ha', 'jack', 'test', 'yes']
>>> list ['ha', 'jack', 'test', 'yes'] >>> listTest.pop() 'yes' >>> listTest ['ha', 'jack', 'test']
>>> listTest ['ha', 'jack', 'test'] >>> listTest.pop(1) 'jack' >>> listTest ['ha', 'test']
>>> listTest ['ha', 'test'] >>> listTest[1] = 'debug' >>> listTest ['ha', 'debug'] >>> listTest[1] = 123 >>> listTest ['ha', 123]
>>> s = ['python', 'java', ['asp', 'php'], 'scheme'] >>> len(s) 4 >>> s[1] 'java' >>> s[2] ['asp', 'php'] >>> s[2][1] 'php'
>>> L = [] >>> len(L) 0
>>> classmates = ('Michael', 'Bob', 'Tracy')
>>> classmates
('Michael', 'Bob', 'Tracy')
>>> classmates[1]
'Bob'
>>> t = (1, 2) >>> t (1, 2)
>>> t = () >>> t ()
>>> t = (1) >>> t 1
>>> t = (1,) >>> t (1,)
>>> t = ('a', 'b', ['A', 'B'])
>>> t[2][0] = 'X'
>>> t[2][1] = 'Y'
>>> t
('a', 'b', ['X', 'Y'])
>>> L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack'] >>> L[0:3] ['Michael', 'Sarah', 'Tracy']
>>> L[1:3] ['Sarah', 'Tracy'] >>> L[:3] ['Michael', 'Sarah', 'Tracy']
>>> L[-2:] ['Bob', 'Jack'] >>> L[-2:-1] ['Bob']
>>> for ch in 'abc': ... print ch ... a b c
>>> from collections import Iterable
>>> isinstance('abc', Iterable) # str是否可迭代
True
>>> isinstance([1,2,3], Iterable) # list是否可迭代
True
>>> isinstance(123, Iterable) # 整数是否可迭代
False
>>> for i, value in enumerate(['A', 'B', 'C']): ... print i, value ... 0 A 1 B 2 C
>>> for x, y in [(1, 1), (2, 4), (3, 9)]: ... print x, y ... 1 1 2 4 3 9
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有