Quick reference guides for Python Programming. Download them for offline access!
# Numbers
x = 5 # int
y = 3.14 # float
# Strings
name = "Alice"
message = 'Hello'
# Booleans
is_valid = True
is_empty = False
# Type conversion
int("10") # Convert to integer
str(42) # Convert to string
float("3.14") # Convert to float
# Numbers
x = 5 # int
y = 3.14 # float
# Strings
name = "Alice"
message = 'Hello'
# Booleans
is_valid = True
is_empty = False
# Type conversion
int("10") # Convert to integer
str(42) # Convert to string
float("3.14") # Convert to float
# Arithmetic
+ - * / // % **
# Comparison
== != > < >= <=
# Logical
and or not
# Arithmetic
+ - * / // % **
# Comparison
== != > < >= <=
# Logical
and or not
# If statement
if condition:
# code
elif other_condition:
# code
else:
# code
# For loop
for item in sequence:
# code
# While loop
while condition:
# code
# If statement
if condition:
# code
elif other_condition:
# code
else:
# code
# For loop
for item in sequence:
# code
# While loop
while condition:
# code
def function_name(param1, param2):
# code
return result
# Call function
result = function_name(arg1, arg2)
def function_name(param1, param2):
# code
return result
# Call function
result = function_name(arg1, arg2)
my_list = [1, 2, 3]
my_list.append(4) # Add to end
my_list.insert(0, 0) # Insert at position
my_list.remove(2) # Remove value
my_list.pop() # Remove last item
len(my_list) # Get length
my_list = [1, 2, 3]
my_list.append(4) # Add to end
my_list.insert(0, 0) # Insert at position
my_list.remove(2) # Remove value
my_list.pop() # Remove last item
len(my_list) # Get length
my_dict = {"key": "value"}
my_dict["new_key"] = "new_value"
my_dict.get("key")
my_dict.keys()
my_dict.values()
my_dict.items()
my_dict = {"key": "value"}
my_dict["new_key"] = "new_value"
my_dict.get("key")
my_dict.keys()
my_dict.values()
my_dict.items()