Learning Python part-9: Python Statements

Python Statements:

Instructions that a Python interpreter executes are called statements. There are different types of statements in the Python programming like Assignment statement, Conditional statement (if..elif…else), Looping statements (For loop, While loop)

Single line statements:

Example:

a = 1

in above example, a = 1, is an assignment statement that assigns variable “a” with a value of 5. Operator ‘=’ is used as assignment operator. 


Python also supports multiple statements in a single line using semicolons

Example:

a = 1; b = 2; c = 3

Multi-line Statements: 


Statements can be extended to one or more lines using parentheses (), braces {}, square brackets [], semi-colon (;), continuation character slash (\) in python. When we need to do long calculations and cannot fit statements into one line, we can use multi-line statements.

Example:

a = (1 + 2 + 3 +
4 + 5 + 6 +
7 + 8 + 9)

Examples using other operators:

Declared using Continuation Character (\):

a = 1 + 2 + 3 + \
4 + 5 + 6 + \
7 + 8 + 9

Declared using parentheses () :

a = ((1 * 2 * 3 * 4 * 5)+ 6 + 7 + 8 + 9)

Declared using square brackets [] :

fruits = [
‘Banana’,
‘Apple’,
‘Mango’, ‘Guava’


Declared using braces {} :

a = {1 + 2 + 3 + 4 + 5
+ 6 + 7 + 8 + 9}

Leave a Reply