Python Practice & Career
Python Cheat Sheet
Everything you need at a glance. Bookmark this Python cheat sheet for quick revision before an exam, interview or coding task.
Variables & Data Types
Python
name = "Aarav" # str
age = 21 # int
price = 99.5 # float
is_active = True # bool
nums = [1, 2, 3] # list
point = (4, 5) # tuple
unique = {1, 2, 3} # set
user = {"id": 1} # dictConditions & Loops
Python
if age >= 18:
print("Adult")
elif age > 12:
print("Teen")
else:
print("Child")
for i in range(5):
print(i)
while age < 25:
age += 1Functions
Python
def greet(name, greeting="Hi"):
return f"{greeting}, {name}!"
square = lambda x: x * xLists & Dictionaries
Python
nums.append(4)
nums.sort()
squares = [x*x for x in range(5)]
user["name"] = "Aarav"
for key, value in user.items():
print(key, value)Files & Errors
Python
with open("data.txt", "w") as f:
f.write("Hello")
try:
n = int(input("Number: "))
except ValueError:
print("Not a number")ℹ️
Want the full explanation behind any line here? Use the sidebar to jump to that lesson in the Python tutorial.
