Python Statement

Instructions that a Python interpreter can eecute are called statements. There are different types of statements in the Python programming language like Assignment statement, Conditional statement, Looping statements etc.

For example- b=1 is assignment statement, if is conditional statement, for and while are looping statements.

Multi-line Statement

Python statements are usually written in a single line. The newline character marks the end of the statement. If the statement is very long, we can explicitly divide into multiple lines with the line continuation character (\).

Python supports multi-line continuation inside parentheses (), braces {}, square brackets [], semi-colon (;)

Example:

Use of  Continuation Character (\):

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

Output:

45 

Python supports multi-line continuation inside parentheses (), braces {}, square brackets [], semi-colon (;)

Use of Parentheses ();

math_result = (1 + 2 + 3 + 4 +
               5 + 6 + 7 + 8 +
               9 + 10)
print(math_result)

Output:

55

Use of Brackets [ ]:

Fruit = ['apple',
          'papaya',
          'banana']
print(Fruit)

Output:

['apple', 'papaya', 'banana']

Use of Braces { }:

countries = {"USA": "United States of America", "IN": "India",
                  "UK": "United Kingdom", "FR": "France"}
print(countries)

Output:

{'USA': 'United States of America',
 'IN': 'India',
 'UK': 'United Kingdom',
 'FR': 'France'}

Use of Semicolon (;):

x = 1; y = 2; z = 3

Python statements are used by the Python interpreter to run the code. It’s good to know about the different types of statements in Python.

Tags