变量名尽量不要和关键字相同,否则容易出歧义

发布时间 2023-04-28 12:06:02作者: sangern

变量名尽量不要和关键字相同,否则容易出歧义

 

>>> xm
['zhang3', 'li4', 'wang5', 'zhao6']
>>> ' '.join(str(e) for e in xm)
Traceback (most recent call last):
  File "<pyshell#183>", line 1, in <module>
    ' '.join(str(e) for e in xm)
  File "<pyshell#183>", line 1, in <genexpr>
    ' '.join(str(e) for e in xm)
TypeError: 'str' object is not callable
>>> str
'a'
>>> del str    # 删除del变量
>>> str
<class 'str'>
>>> ' '.join(str(e) for e in xm)
'zhang3 li4 wang5 zhao6'