Python list

A list is well known to be a comma-separated data
structure whose contents can be of the same type:

l = [1,2,3,4,5,6]  #都是整数

Can also be of different types.
Similar to the way C language accesses arrays, you can use subscripts to access list elements:

l[0]  #1
l[5]  #6
l[6]  #报错,越界

You can also intercept parts to get a new list:

l[2:5]  #3,4,5
l[2:]   #3,4,5,6
l[:4]   #1,2,3,4
l[2]    #注意特殊情况,这里只截取了l的一个长度,值为3,但是是一个整数类型,并不是list类型。要作为list类型需要强制转换:list(l[2])

Reference: https://jizhi.im/course/dl_python/2

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325698352&siteId=291194637