Statements in Python

Statements: It is a command or instruction that the python interpreter can understand and execute.
If we type a statement on the command line, Python executes it.
We may also write a sequence/group of statements in a script/program.

Types of Statement: There are 3 types of statements:
1) Empty Statement
2) Simple Statements
3) Compound Statements / Block

Empty Statement: It is the simplest statement in python. It does nothing.
Empty statement in python is pass which is written as:
pass
It acts as a dummy statement.
Whenever python encounters a pass statement, python does nothing and control moves to the next line.
It is written where the python syntax needs a statement but we don’t want to do anything. Example:

while True:
    response=input("Have you learnt Python? ")
    if response.upper()!="YES":
        pass
    else:
        print("Thanks for learning from wwww.gargscademy.com")
        break

Output:

Have you learnt Python? no
Have you learnt Python? No
Have you learnt Python? NO
Have you learnt Python? yes
Thanks for learning from wwww.gargscademy.com

Simple Statements: These are the simple single line statements that are executed as an individual statement in python.
Example:
1) Assignment Statements like
b=30
2) Input Statements like
num=int(input(“enter a number”))
3) Printing Statements like
print(“Welcome to Gargs Academy”)
4) Processing statements like
sum= a + b
etc.

Block / Compound Statement It is a group of statements (piece of python program text) executed as a unit.
The following are blocks:
1) a module
2) a function body
3) a class definition
4) each command typed interactively is a block.
5) if block
6) else block
7) for block
8) while block

Compound statements are written as
compound statement header:
indented body consisting of statements
may be a single statement or a group of statements.


1) First line of compound statement is header which contains a colon (:) at the end.
2) Contained Statements are not written in the same column as the control statement, rather they are indented to the right side and together they are called a block.

Indentation It refers to the (spaces and tabs) that are used at the beginning of a statement.
It is used to create groups/blocks/compound statements in python.
The statements with the same indentation belong to the same group/block.
For Example

a=int(input("enter any number"))
print("You have entered" , a)
if a==9467863365 :
    print("Contact for Math & Computers at", a)                   #indentation
    print("Gargs Academy")                                        #indentation
    print("Sonipat")                                              #indentation
else :
    print("You have got wrong number")                            #indentation
    print("Visit site www.gargsacademy.com to get contact no")    #indentation

Output 1:

enter any number9467863365
You have entered 9467863365
Contact for Math & Computers at 9467863365
Gargs Academy
Sonipat

Output 2:

enter any number653542
You have entered 653542
You have got wrong number
Visit site www.gargsacademy.com to get contact no
error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.