Code indentation has been given great importance in Python. In Python, Code Indentation is used for functions, classes, loops and control statements.
Code indentation is used instead of curly braces ({}) in Python.
In python when the colon (:) or delimiter is given in code indentation then tab () is automatically given by interpreter on the next line.
Source Code:
def func ():
a = 5
print (a)
func ()
Output:
5
list = [1, 5, 8, 9]
for i in list:
print (i)
Output:
1
5
8
9
class myClass:
def func ():
a = 5
print (a)
myClass.func ()
Output:
5
Code indentation is used instead of curly braces ({}) in Python.
In python when the colon (:) or delimiter is given in code indentation then tab () is automatically given by interpreter on the next line.
Function
Source Code:
def func ():
a = 5
print (a)
func ()
function |
Output:
5
For loop
Source Code:list = [1, 5, 8, 9]
for i in list:
print (i)
for loop |
Output:
1
5
8
9
Class
Source Code:class myClass:
def func ():
a = 5
print (a)
myClass.func ()
class |
5
0 Comments