美文网首页我的python学习笔记
Lists and Membership Operaters

Lists and Membership Operaters

作者: 用户高卢总督 | 来源:发表于2018-07-13 22:43 被阅读0次

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

相关文章

网友评论

    本文标题:Lists and Membership Operaters

    本文链接:https://www.haomeiwen.com/subject/zatepftx.html