标签:内容 优化 value 64位 display str 默认 范围 isp
上节课内容补充
1 name = "李璐" 2 3 for i in name: 4 print(i) # 循环的每一个字符串是"字符" 5 """ 6 李 7 璐 8 """ 9 bytes_list = bytes(i, encoding="utf-8") 10 print(bytes_list) # 默认每一个字节都是16进制表示 11 """ 12 b‘\xe7\x92\x90‘ 13 """ 14 for b in bytes_list: 15 print(b) # 默认每一个字节都是10进制表示 16 print(bin(b)) # 2进制 17 """ 18 231 19 0b11100111 20 146 21 0b10010010 22 144 23 0b10010000 24 """
1 t = (11, 22, ["alex", {"k1": "v1"}]) 2 print(t) 3 # (11, 22, [‘alex‘, {‘k1‘: ‘v1‘}]) 4 t[2].append(123) 5 print(t) 6 # (11, 22, [‘alex‘, {‘k1‘: ‘v1‘}, 123])
1 # 创建 2 a1 = {"k1": 123} 3 print(1, a1) 4 # {‘k1‘: 123} 5 6 a2 = dict(k1=123, k2=456) 7 print(2, a2) 8 # {‘k1‘: 123, ‘k2‘: 456} 9 10 li = [11, 22, 33] 11 new_dict = dict(enumerate(li)) 12 print(3, new_dict) 13 # {0: 11, 1: 22, 2: 33} 14 15 # 特殊功能 16 dic = {"k1": 11, "k2": 22, "k3": 33, "k4": 44} 17 n = dict.fromkeys(["k1", "k2", "k3"], "alex") 18 print(4, n) 19 # {‘k1‘: ‘alex‘, ‘k3‘: ‘alex‘, ‘k2‘: ‘alex‘} 20 21 n1 = dict.fromkeys(["k1", "k2", "k3"], []) 22 n1["k1"].append("x") 23 print(5, n1) 24 # {‘k1‘: [‘x‘], ‘k2‘: [‘x‘], ‘k3‘: [‘x‘]} 25 26 n2 = {‘k1‘: [], ‘k2‘: [], ‘k3‘: []} 27 n2["k1"].append("x") 28 print(6, n2) 29 # {‘k1‘: [‘x‘], ‘k2‘: [], ‘k3‘: []}
1 class MyInt(object): 2 def __init__(self): 3 print("init") 4 def __call__(self, *args, **kwargs): 5 print("ok") 6 7 obj = MyInt() 8 # 输出结果:init 9 obj() 10 # 输出结果:0k
标签:内容 优化 value 64位 display str 默认 范围 isp
原文地址:http://www.cnblogs.com/grissom/p/6361169.html