L2 Variables Assignment Data Types
L2 Variables Assignment Data Types
What is a variable in
Python?
• What is a variable?
A variable is a name/identifier that represents a value
in the computer’s memory.
age = 25
x = x+1
• x = 3.9 * x * (1-x)
• x = 5
>>> x = 3
>>> y = 4
>>> print(x, y)
3 4
>>> x, y = y, x
>>> print(x, y)
4 3
Floats:
Numbers with a decimal point are called floats or
floating-point values.
str: string/text
The int() and float() functions work only if the item that is being converted
contains a valid numeric value. If the argument cannot be converted to the
specified data type, an error occurs.
L4 Variables and numeric data types - 29
Find Data Type
• We can use the type function to find the data type
>>> type(4)
<class ‘int’>
• We learned how to
– assign values to variables
– do multiple assignments in one statement
– Limitations of data types