in [12]:#是否存在某元素
yunchuang = 'xy'
print (’x' in yunchuang)
print('w' in yunchuang)
Ture
False
in [13]:#实例,检查提供的用户名feng是否包含在列表中
users = ['feng','meng'.'ru',]
input('enter your users name:') in uesrs
in [14]:#创建列表的几种方式
list1 = ['yun','chuang',30,40]
list2 = [1,2,3,4,5]
list3 = ["a","b","c","d"]
print(list1)
print(list2)
print(list3)
['yun','chuang',30,40]
[1,2,3,4,5]
['a','b','c','d']
#访问元素列表 list1 =['yun','chuang',2,20] list2 =[1,2,3,4,5,6,7,] print("list[0]:",list[0]) #访问单个元素 print("list2[1:6]:",list2[1:6])#访问多个元素
list[0]: yun
list[1;6]:2,3,4,5,6,]
给列表切片赋值
name= list('yuanchuang') print(name) name[3:]= list('python') print(name)
元组中的数列不可以修改
#删除列表元素
names =['nan','jing','yun','chuang','da','shu','ju']
del names [3]
names
['nan','jing','yun','chuang','da'.'shu','ju']
#字典创建
dict ={'yun':'123','chuang':'456','big data':'789'} #索取字符串 取值字符串
dict1 = {’yunchuang‘:456} #索取字符串 取值字符串
dict2 = {'yunchuang':123,100:37}#索取字符串 取值字符串
print(dict)
print(dict1)
print(dict2)
{'yun':'123','big data':'789','chuang':'456'}
{'yunchuang':456}
{'yunchuang':123,100:37}