π Common Python Syntax Bug Issues
1. Indentation Errors
if True:
print("Hello") β IndentationError
print("Hello") β
Correct indentation
2. Missing Colons
if x == 5 β SyntaxError
if x == 5: β
Correct
3. Misusing = vs ==
x = 5
if x = 5: β SyntaxError
if x == 5: β
Correct
4. Case Sensitivity
name = "Alice"
print(Name) β NameError (Python is case-sensitive)
print(name) β
Correct
5. Unclosed Strings or Brackets
msg = "Hello β SyntaxError
msg = "Hello" β
Correct
6. Wrong Indentation in Functions
def test():
print("oops") β IndentationError
print("works") β
Correct
7. Using Keywords as Identifiers
class = "Math" β SyntaxError
class_name = "Math" β
Correct
8. Trailing Symbols
print("Hi"!) β SyntaxError
print("Hi!") β
Correct
9. Improper Imports
from . import mymodule β outside a package
import mymodule β
Correct
10. Line Break Issues
total = 1 +
2 + 3 β SyntaxError
total = (1 +
2 + 3) β
Correct
Post #1025
1.1K
- β€ 1