Python basics cheat sheet
Printing, variables, types and arithmetic. Each example shows the code and exactly what it prints.
print("Hello") | Hello | Show text |
print("a", 5, sep="-") | a-5 | Several values with a separator |
x = 7 print(x, type(x).__name__) | 7 int | A variable and its type |
print(7 / 2, 7 // 2, 7 % 2) | 3.5 3 1 | Division, whole division, remainder |
print(2 ** 10) | 1024 | Power |
print(int("42") + 1, float("2.5")) | 43 2.5 | Convert text to numbers |
print(str(3) + "4") | 34 | Convert a number to text |
name = "Riya" print(f"Hi {name}, {3 * 4} marks") | Hi Riya, 12 marks | f-string |
print(round(3.14159, 2), abs(-5)) | 3.14 5 | Rounding and absolute value |
print(5 > 3 and 2 == 2, not True) | True False | Comparisons and logic |
Py-CRAFT cheat sheet. © 2026 Dr. Saptarshi Das (PhD, IIT Kharagpur | ME, Jadavpur University). All rights reserved.