开发者

what is the most frequent error in python for a beginner? [closed]

开发者 https://www.devze.com 2023-02-22 20:06 出处:网络
开发者_开发问答As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely so
开发者_开发问答 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号