Python Variables Cheatsheet
Python Variables Cheatsheet
1. Assigning Variables
Variables in Python are used to store data. To create a variable, use the assignment
operator = to assign a value to a variable name.
# Assigning a variable
x = 10
name = "Alice"
2. Data Types
Python has several built-in data types, including:
str : Strings
bool : Booleans
list : Lists
tuple : Tuples
dict : Dictionaries
3. Type Checking
You can use the type() function to determine the data type of a variable.
4. Type Conversion
Convert between data types using built-in functions like int() , float() , str() , and
bool() .
# Type conversion
x = 42
float_x = float(x)
print(float_x) # Output: 42.0
# Arithmetic operations
x = 10
y = 5
add = x + y
sub = x - y
mul = x * y
div = x / y
# String operations
first_name = "Alice"
last_name = "Smith"
full_name = first_name + " " + last_name