f"{!r}"
- 等价与 '{!r}'.format()
- 输出会带上引号
- 和 print('%r' % a)相同
a = '2'
print(f"{a}")
print("{}".format(a))
print(f"{a!r}")
print("{!r}".format(a))
输出:
[arg,...] *arg, [arg,...] =
- 对=号右边解包后,对=号左边的固定变量进行赋值(从左往右),剩下的给*arg
- *arg可为None
- 固定变量个数应不超过=号右边解包后值的个数
my = 'b', 'c'
print(my)
*x, = my
print(f"x:{x}")
*y,z = my
print(f"y:{y}, z:{z}")
*x1, x2, x3 = my
print(f"x1:{x1}, x2:{x2}, x3:{x3}")
*y1, y2, y3, y4 = my
输出:
enumerate
- 返回一个可迭代对象
- (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
- 迭代时,index不变,但seq是可以变化的
items = [1, 2, 3, 4, 5]
for idx, item in enumerate(items):
items.remove(item)
print(items)
输出:
dic[1]和dic[1.0]
- python字典中hash(1) == hash(1.0) = hash(True) == 1 且11.0True
- 所以1, 1.0, True在dict中是属于同一个key
isinstance(True, Int)
- isinstance(False, Int)返回True
- bool继承至int
dis
- 显示反汇编
import dis
def func(a, b):
a -= b
return a
dis.dis(func)
输出: