Professional Documents
Culture Documents
Sally
x = 4 # x is of type int
x = "Sally" # x is now
of type str
print(x)
x = "John" John
print(x)
x = 'John' John
print(x)
Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age,
carname, total_volume). Rules for Python variables:
x, y, z Orange
= "Orange", "Banana", "Cherry"
Banana
print(x)
print(y) Cherry
print(z)
And you can assign the same value to multiple variables in one line:
x = y = z = "Orange" Orange
print(x)
print(y) Orange
print(z) Orange
Output Variables
The Python print statement is often used to output variables.
To combine both text and a variable, Python uses the + character:
You can also use “ “ to put a blank character between two variables
Example Coding: Output:
x = 5 15
y = 10
print(x + y)
If you try to combine a string and a number, then Python will give you an error:
x = 5 Error
y = "John"
print(x + y)