5 Réponses
+ 9
Indentation marks a block of code, just like {} do in other languages.
Other languages:
if(condition) {
print('inside block');
print('inside block');
print('inside block');
}
print('outside block');
Python:
if condition:
print('inside block')
print('inside block')
print('inside block')
print('outside block')
+ 6
Because it doesn't use curly braces for example.
+ 4
if True:
print ("hi")
print ("hello")
if True:
print("hi")
print("hello")
+ 4
Because we don't use curly braces for defining functions and classes if statements in python.
So using indentation is the way we use to make compiler understand start or end of functions and classes and if statements .
+ 3
otherwise the code cant tell what is in the if statement and what not