what is the most frequent error in python for a beginner? [closed]
What do you think is the most frequent errors or pitfalls a beginner may encounter when he use python?
Forgetting the self
keyword in classes.
Either in method declaration and/or when referencing class members (specially for someone coming from .NET/Java/..
world where "equivalent" this
keyword can be omitted).
My guess would be:
SyntaxError: invalid syntax
That could be IndentationError
resulting from incorrect mix of tabs and spaces in code and/or incorrect code formatting.
Do you mean errors or pitfalls? For the later I'd say: passing mutable objects as default values:
def foo(bar=[]):
bar.append("foobar")
return bar
foo()
foo() # Wait! Why am I getting ['foobar', 'foobar'] here? D'Oh ;)
After answering twice the same question. It looks like the more surprising thing it's when the script is named like the module they want to import.
精彩评论