网站制作学习网Python→正文:python := 赋值运算符
字体:

python := 赋值运算符

Python 2024/9/16 23:07:57  点击:不统计


 python中的赋值运算符,可以方便的使用临时变量
看下面代码:

tmp = [1,2,3]
# 第一种
if len(tmp) > 0:
    print("len > 0,len is %d"%len(tmp))
# 第二种   
l = len(tmp)
if l > 0:
    print("l > 0,l is %d"%l)
   
# 第三种使用:=赋值运算符,可以避免重复调用函数
if (l := len(tmp)) > 0:
    print("l > 0,l is %d"%l)

   

·上一篇:python loguro 日志扩展包 >>    ·下一篇:ImportError: The _imagingft C module is not installed >>
推荐文章
最新文章