In: Computer Science
Python programming language uses indentation as its building block of syntax.
As seen in maximum of other programming languages, flower brackets are used to limit or define the scope of code. For example scope of function or scope of if-else block or scope of for loop.
But in python it is entirley different. It follows indentation to define the scope of its code parts.
Indentation means proper spacing.
For example i will give an example of for loop in both java and python languages. Iam adding java code to let you understand the syntax difference between python and other major programming languages.
code to print Hi 10 times
In java
for(int i=0;i<10;i++){
System.out.println("Hi");
}
see in above code, java has braces to define its scope to for loop.
In Python
for i in range(10):
print("Hi")
print("Bye")
See in above code, python has indentation rule to define its scope
to for loop.
You can see a space infront of print in the second line. It keeps
the print("Hi") statement inside the for loop.
print("Bye") has no space infront of it and it is relativly placed
with for loop. So it wont be inside for loop. This statement will
be print into console after printing "Hi" 10 times.
Above given example was simple one.
Now i will show you example of if-else block inside a for loop.
for i in range(10):
if i%2==0:
print("Even")
else:
print("Odd")
In the above code you can see if-else statement inside for
loop.
If statement is placed after giving a proper space inside for loop, which must be exactly followed by else statement. We can easily construct syntax in python keeping indentation and proper spacing and relative place of statement starting point.
Feel free to ask if you find any difficulty
Please upvote if this answer is helpfull.