Lists and Membership Operaters

Data Type

Lists can contain any mix and match of the data types you have seen so far.

list_of_random_things= [1,3.4,'a string',True]#integer,float,string,boolean

print(list_of_random_things[0])

# attention it is 'True' not 'Ture'

Print Lists

The location of data


list_of_random_things= [1,3.4,'a string',True]

print(list_of_random_things[len(list_of_random_things)])

# IndexError: list index out of range

list_of_random_things= [1,3.4,'a string',True]

print(list_of_random_things[len(list_of_random_things)-1])

# output:True

Print from last one


>>>list_of_random_things[-1]

True

>>>list_of_random_things[-2]

a string

Print from x->y


>>>list_of_random_things= [1,3.4,'a string',True]

>>>list_of_random_things[1:2]#or[(from the first one to the second if the ''is behind 2 it is the second to the last one):2]

[3.4]

Judge

in or not in


>>>'this'in'this is a string'

True

>>>'in'in'this is a string'

True

>>>'isa'in'this is a string'

False

>>>5notin[1,2,3,4,6]

True

>>>5in[1,2,3,4,6]

False
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • 明天要去爬野线,但报名人数不足20人,一直很担心会不会取消,这可是我盼望已久的出游,心中一直忐忑不安,一大早都抱着...
    犹若男生阅读 412评论 0 0
  • New York is 3 hours ahead of California but it does not m...
    本就无名阅读 203评论 0 0
  • Ivybear阅读 251评论 0 0
  • 泉眼无声惜细流,树阴照水爱晴柔。 小荷才露尖尖角,早有蜻蜓立上头。 去湿地公园看到满池荷花,不禁想起这首杨万里的《...
    峤语阅读 355评论 0 3