DEV Community

Discussion on: 10 must-know patterns for writing clean code with Python🐍

Collapse
 
svschoenherr profile image
Sven Schönherr • Edited

For loop should also not be indented...

Collapse
 
jmccabe profile image
John McCabe

There's always a possibility that's an issue with the page formatter for code. I know Confluence can be a bit funny about that if you paste into a code block.

Collapse
 
a5537 profile image
A5537 • Edited

Maybe this indent decided to leave the print statement (where it is destined to be)

for x in c:
print(x)

# Recommended
cities = [“UK”, “USA”, “UAE”]
    for city in cities:
        print(city)
Enter fullscreen mode Exit fullscreen mode

and moved in with that for loop neighbor against all odds.

Seriously, indent really matters in Python. As well as the case (especially for keywords), so Pass instead of pass

# Recommended
def fetch_users(): 
    # do something
    Pass
Enter fullscreen mode Exit fullscreen mode

will trigger a NameError unless there is a variable named Pass.

And speaking of technical debt, these two kinds of bugs (wrong indentation and case incosistency) in poorly written Python code are sneaky enough to go unnoticed since they may not trigger any error messages in some cases.

Thread Thread
 
potasiak profile image
Sebastian Potasiak

Also, the quotation marks in the cities list are not " (\x22) but “ (\u201C) and ” (\u201D) unicode characters. It would raise SyntaxError.