Block and Statement in Python

Block and Statement

A 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. Instructions that a Python interpreter can execute are called Statements. 

block and statement in python

Block and Statement

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 (\).

Example : 

  • def add(a,b): #Block 
  • P=’PrepInsta’ #statement
implementation of blocks and statements in Python

Implementation of Block and Statement in Python

Run
#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

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription