CM4 Python Variables
CM4 Python Variables
CM4 Python Variables
Variables
Co
in s
2
Variables
Value: The number of coins in the box is the value of the variable.
The number inside can change as we add or take away coins.
Variables
Variable
(the container)
Variable Name
Value
(label for the container)
(stored inside the container)
Coins = 3
Read from left to right:
“The variable Coins is assigned to the
integer 3” 4
Warm-up Activity
Our Variables
● age =
● name =
● song =
● food =
● number =
Literals
Numeric Literals
Boolean Literals
Special Literal
• enemy = None
weapon = None
artifacts = None
armor = None
Assignment
Statement
– x=3.1414
– print(x)
– y=143
– print(y)
Identifiers
import const.py
Print(const.PI)
Print(const.GRADE)
Save the above codes to main.py
Assigning Input
• a=5
• float(a) ;integer to float
• str(a) ;integer to string
• b = "20"
• float(b) ; string to float
• int(b) ; string to integer
• c = 30.0
• int(c) ;float to integer
• str(c) ;float to string
Simultaneous
Assignment
• x=2+3
This is an expression that uses the addition operator
• print(x)
• print(5 * 7)
This is an expression that uses the multiplication operator
• print("5" + "7")
This is an expression that uses the addition operator but to concatenate strings
together
Expressions
x=6 • print(x*y)
y=2 • print(x**y)
print(x - y) • print(x%y)
print(x/y)
• print(abs(-x))
print(x//y)
Next Meeting
Arithmetic Operators
Comparison Operators
Logical Operators
Bitwise Operators
Assignment Operators
Identity Operators
Membership Operators
Output Formatting
Question
Activity