编程语言
首页 > 编程语言> > Python3.8 :=海象运算符简单介绍

Python3.8 :=海象运算符简单介绍

作者:互联网

海象运算符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)")

 

标签:海象,len,运算符,123,EXPERIMENTAL,print,Python3.8
来源: https://www.cnblogs.com/mik-hello/p/14999418.html