[Tutor] Lists

eizetov at gmail.com eizetov at gmail.com
Sat Jun 11 06:56:08 CEST 2011


Vincent, you should also try to avoid naming your lists a 'list'. There's a  
couple dozen words in Python that are reserved 'for system use':

>>> import keyword
>>> print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

'List' is actually not listed here, however, using it as a variable name is  
still bad:

>>> list('spam')
['s', 'p', 'a', 'm']
>>> list = '42'
>>> list('spam')
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
list('spam')
TypeError: 'str' object is not callable

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110611/06a8f83a/attachment.html>


More information about the Tutor mailing list