What is Python Statement?
What is a Statement in Python?
In Python, a statement is a code that the interpreter runs or the instructions that the interpreter follows. A statement like z = 5 sends the value 5 to the variable z. In Python, statements come in a variety of forms, including while, if, and so on.
Multi-line Statement
The continuation character () in Python is used to prolong a statement across multiple lines. As a result, the statement is now a multi-line statement.
Parentheses (), braces (), or square brackets [ ] can also be used to define a multi-line statement. A semicolon can also be used to specify numerous statements on a single line.
-
Example using Continuation Character (\)
If the user wishes to compute the sum of many numbers, he can do so using the continuation character in a multi-line expression. Consider the following illustration:
x = 1 + 2 + 3 + \
2 + 3 + 1 + \
3+ 9 + 1
-
Example using parentheses ()
Multiline statements can also be declared using parentheses ()
. Consider the following example:
x = (11 + 12 + 13 +
42 + 25 + 26 +
73 + 38 + 39)
-
Example using braces {}
Braces can also be used to express multi-line statements. Consider the following illustration:
x = { 2 + 3 + 1 +
4 + 15 + 6 +
7 + 18 + 9}
-
Example using square brackets [ ]
Square brackets []
can also be used to define a multi-line statement. Consider the following illustration:
x = [31 + 23 + 53 +
45 + 52 + 56 +
7 + 28 + 29]
-
Example using a semicolon (;)
A semicolon can also be used to specify numerous statements on a single line. Consider the following illustration:
x = 2; y = 3; z = 4