海象运算符python 3.8支持
1.实现赋值
EXPERIMENTAL = 123 if c_o := EXPERIMENTAL: print(c_o) # 结果: # 123
2. 避免len()方法运行两次,提高了运行速度.
a = (1, 2, 3, 4, 5) if (n := len(a)) > 3: print(f"List is too long ({n} elements, expected <= 10)")
2023-11-10 09:39:04
1.实现赋值
EXPERIMENTAL = 123 if c_o := EXPERIMENTAL: print(c_o) # 结果: # 123
2. 避免len()方法运行两次,提高了运行速度.
a = (1, 2, 3, 4, 5) if (n := len(a)) > 3: print(f"List is too long ({n} elements, expected <= 10)")