Unit1 Topic Variables, Expressions and Statements
Unit1 Topic Variables, Expressions and Statements
Topic - Variables
By
Ms.T.R.Thamizhvani
VARIABLES:
Statements:
• Instructions that a Python interpreter can executes are called
statements.
• -A statement is a unit of code like creating a variable or displaying a
value.
• >>> n = 17
• >>> print(n)
• Here, The first line is an assignment statement that gives a value to n.
• The second line is a print statement that displays the value of n.
Expressions:
An expression is a combination of values, variables, and operators.
In tuple packing, the values on the left are ‘packed’ together in a tuple:
• >>> b = ("George", 25, "20000") # tuple packing
In tuple unpacking, the values in a tuple on the right are ‘unpacked’ into the variables/names on the right:
• >>> b = ("George", 25, "20000") # tuple packing
• >>> (name, age, salary) = b # tuple unpacking
• >>> name
• 'George'
• >>> age
• 25
• >>> salary
• '20000'
The right side can be any kind of sequence (string, list, tuple)
Example: