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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.