+ 1
Please, I need someone to explain to me the indentation of the else statement.
9 Réponses
+ 5
Rebecca ,
a general recommendation about indentation of python code:
>>> a good and correct indentation gives a good readability of the code. it is recommended to use 4 spaces per indentation level.
this is the official style guide for python (PEP 8):
https://peps.python.org/pep-0008/#indentation
+ 3
Instead of clicking 2 or 3 times for space I would suggest use tab which takes 4 space. If you use tab, indentation will be always correct
+ 2
Rebecca if an else statements also have the same indentation, but a for loop can also have an else statement.
+ 2
A͢J I'm old fashioned. I cannot have all those spaces😂😂
+ 1
It's more convenient doing it this way instead.
contacts = dict(contacts)
a = input()
if a in contacts:
print(a + " is " + str(contacts[a]))
else:
print("Not found")
+ 1
For loop statement and the else statement have the same indentation but i was expecting the if and else statements to have the same indentation.
+ 1
I think going by the default in most Python IDLE is good way to have it on codes.