Block and statement in Python

Block and Statement

What is a Block and statement in python ?
block is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition. Each command typed interactively is a block. 

Statement : Instructions that a Python interpreter can execute are called statements. 

Example : 

  • def add(a,b):
    • #Block 
  • P=’PrepInsta’ #statement
block and statement in python

Block :

  • A Python program is constructed from code blocks.
  •  A script file (a file given as standard input to the interpreter or specified as a command line argument to the interpreter) is a code block. 

Statement :

  • There are different types of statements in the Python programming language like Assignment statement, Conditional statement, Looping statements etc. 
    • P=’PrepInsta’ #assignment statement
  • Multi-Line Statements: In Python we can make a statement extend over multiple lines using braces {}, parentheses (), square brackets [], semi-colon (;),  and continuation character slash (\).
implementation of blocks and statements in Python

Implementation of Block and Statement in Python

#Block
def add(A,b):
    #block 
Class Student:
    #block
    def(self,name,roll):
        #block 


#Statements
#Continuation Character (\):
s = 1 + 41 + 48 + \
    4 + 51 + 6 + \
   50 + 10

#parentheses () :
n = (17 * 5 * 4 + 8 )

#square brackets [] :
cars = [‘BMW’,
          ‘THAR’,
          ‘FERARI’]

#braces {} :
x = {1 + 2 + 3 + 4 + 5 + 6 +
     7 + 8 + 9}

semicolons(;) :
a= 2; b = 3; c = 4