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

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

 

>>> 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'

  

posted @ 2023-04-28 12:02  sangern  阅读(42)  评论(0编辑  收藏  举报