故事会在线阅读,殷悦老公,松武漫画
an inch is worth a pound of gold, an inch of gold is hard to buy an inch of time.
when the scale of data is so large that we have to pick a short of the content, the best way is to use slice.
>>>l=range(1,101) >>>l[1:] #until the end >>>l[:101] #from the first >>>l[1:100] >>>l[1:101:2] #pick one in two
>>>l=range(1,101) >>>l[-1:] >>>l[:-1] >>>l[-5:-1] >>>l[-46::5]
in python, iterations are done with "for ... in ...". 'for' loop in python can be used not only on lists and tuples, but alse on any other iterable objects. therefore, the iterative operation is for a collection, whether the collection is ordered or unordered, we can always use the loop to extract each element of the collection in turn. the collection is a data structure containing a set of elements, and we have learnt list, tuple, set, dict, str, unicode.
for index, name in enumerate(l): print index, '-', name
>>> zip([10, 20, 30], ['a', 'b', 'c']) [(10, 'a'), (20, 'b'), (30, 'c')]
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新手学习Python2和Python3中print不同的用法
Python基于os.environ从windows获取环境变量
网友评论