Python Learning Day2

 

4.删除

 

5.keys.values.items

print(dict1.keys())
print(dict1.values())
print(dict1.items())

 

6.循环

for key in dict1:
    print(key)

7.update()

print(dict1)
dict2={‘work':'student'}
#dict2加入dict1字典中
dict1.update(dict2)
print(dict1)

 

元组类型(在小括号内,以逗号隔开存放多个值)

 

tuple1=(1,2,3)
print(tuple1)

1.按照索引值

print(tuple1[2])

2.切片,顾头不顾尾

print(tuple1[0:6])
print(tuple1[0:6:2])

3.长度

print(len(tuple1))

4.成员运算 in 和 not in

print(1 in tuple1)
print(1 not in tuple1)

5.循环

for line in tuple1:
    print(line)

 

集合类型

在{ }内,以逗号隔开,可存放多个值,但集合默认去重功能

set1={1,2,3,4,1,2,3,4}
print(set1)

集合是无序的

set1=set()
set2={}
print(set1)
print(set2)
set2['name']='tank'
print(type(set2))

 

上一篇:6.12-python学习


下一篇:Python学习之路--dict