元祖(tuple)
tu = (11,"umbrella",(25,5),[(45,89),11],True,22,33,)
tu[3][0] = 123
print(tu)
li = [125,1,8,9,125,75] v = "umbrella" v1 = tuple(v) v2 = tuple(li) print(v1,v2)
元祖类中的功能
tu = (11,"umbrella",(25,5),[(45,89),11],True,22,33,11,) v = tu.count(11) print(v)
tu = (11,"umbrella",(25,5),[(45,89),11],True,22,33,11,) v = tu.index(22) print(v)
dict = {"k1":"v1","k2":"v2"} v1 = "k1" in dict v2 = "k1" in dict.keys() v3 = "v1" in dict.values() print(v1,v2,v3)
字典(dict)
info = {"a1":"b1","a2":"b2",857:True,"v":[4,8,6],666:(44,66),True:"123",}
print(info[857])
print(info["a1"])
print(info["v"][0])
del info["a1"]
print(info)
info = {"a1":"b1","a2":"b2",857:True,"v":[4,8,6],666:(44,66),} for v1 in info: print(v1) for v2 in info.keys(): print(v2) for v3 in info.values(): print(v3)
for v4,v5 in info.items():
print(v4,v5)
dict 类中的方法
info = {"a1":"b1","a2":"b2",857:True,"v":[4,8,6],666:(44,66),} info.clear() print(info)
info = {"a1":"b1","a2":"b2",857:True,"v":[4,8,6],666:(44,66),} info.copy() print(info)
info = {"a1":"b1","a2":"b2",857:True,"v":[4,8,6],666:(44,66),} v = dict.fromkeys(["223","sdf",666,"999"],1) print(v)
dict = {"a":"b",857:True,"v":[4,8,6],666:(44,66),} v1 = dict.get("a") v2 = dict.get(456) v3 = dict.get(456,"错误") print(v1,v2,v3)
info = {"a1":"b1","a2":"b2",857:True,"v":[4,8,6],666:(44,66),} for v1 in info: print(v1) for v2 in info.keys(): print(v2) for v3 in info.values(): print(v3) for v4,v5 in info.items(): print(v4,v5)
dict = {"a":"b",857:True,"v":[4,8,6],666:(44,66),} v1 = dict.pop(857) print(dict,v1) v2 = dict.pop(857,"换了") print(dict,v2)
dict = {"a":"b",857:True,"v":[4,8,6],666:(44,66),} v1,v2 = dict.popitem() print(dict) print(v1,v2)
dict = {"a":"b",857:True,"v":[4,8,6],666:(44,66),} v1 = dict.setdefault("a",666) v2 = dict.setdefault("umbrella",666) print(dict,v1) print(dict,v2)
dict = {"k1":"v1","k2":"v2"} dict.update(k1=1,k2=2,k3=666) print(dict)
布尔值(bool)
v1 = bool(None) v2 = bool("") v3 = bool(()) v4 = bool([]) v5 = bool({}) v6 = bool(0) print(v1,v2,v3,v4,v5,v6)
原文:https://www.cnblogs.com/umbrellalearner/p/15090839.html