Jun 18, 2020
5 most common mistakes by python developers
Python is one of the most popular object-oriented, high-level programming language with dynamic semantics. It's simple syntax can mislead Python developers, especially those who are newer to the language.
In programming, you will always face coding mistakes, and you might spend more time to fixing your mistakes. Studies reveal that most of these mistakes happen to be the side effects of common misconceptions carried from the past programming experiences.
If you know about the most frequent types of programming errors that people make with Python, then Python programming will be more easy for you. So, let's find these common mistakes -
1. Incorrect indentation
In Python, everything relies on indentation. Newbie programmers who didn't follow indentation in the previous programming language, in python it will be a nightmare for them. If you find that your program not executing properly, then start reviewing the indentation you're using.
2. Expressions for defaults for function arguments
Python allows you to specify the default value of a function argument, which is a great feature, but lead to some confusion when the default value is mutable. The common mistake is to think that function will return the default expression each time the function is called without supplying a value for the optional argument. In python, the default value for a function argument is only evaluated once, at the time that the function is defined.
3. Incorrect logical operator
Logical operators create lots of problems for developers. Learn to use and to determine when both operands must be True and or when either of the operands can be True.
4. Misunderstanding scope rules
If you aren't aware of Python scoping rules, then there is a high probability of making mistakes. Python scope resolution is based on Local, Enclosing, Global, Built-in rule. When you assign a variable in a scope, that variable is automatically considered by Python as a local scope and shadows of any similarly named variable in any outer scope. Many get surprised by an UnboundLocalError in previously working code when it is modified by adding an assignment statement somewhere in a function.
5. Wrong capitalization
Python is case sensitive and it can differentiate between MyVariable, myvariable and MYVARIABLE. Always check capitalization when you are using variables or/and functions.