ID Academia · Python
Python commands — cheat sheet
Every command from the 03.11–13.11 lessons: what it does and a short example. Then common mistakes and a quiz.
Input, output, typesLesson 03.11.2026
| Command | What it does | Example |
|---|---|---|
print(a, b) | Output; puts a space between arguments | print(5, "+", 3) # 5 + 3 |
"\n" | Line break inside text | print("A\nB") |
input("text") | User input — ALWAYS a string | n = input("Number: ") # "5" |
int(x) / float(x) / str(x) | Type conversion | int("7") → 7, float("2.5") → 2.5, str(5) → "5" |
type(x) | Shows the type | type((1, 2)) # <class 'tuple'> |
.isdigit() | True if the string has only digits | "12".isdigit() → True, "-5".isdigit() → False |
# / """ """ | Comment / docstring describing a file or function | # Check input |
OperatorsLesson 03.11.2026
| Command | What it does | Example |
|---|---|---|
+ - * / | Arithmetic; / always returns float | 7 / 2 → 3.5 |
== != > < >= <= | Comparison, result True/False | num1 > num2 |
and / or / not | Logical AND / OR / NOT | a.isdigit() and b.isdigit() |
= | Assignment (not ==) | result = 5 |
Conditions and exitLesson 03.11.2026
| Command | What it does | Example |
|---|---|---|
if / elif / else | Pick a branch; stops at the first match | if x > 0: ... elif x == 0: ... else: ... |
match / case | Compare one variable to options (Python 3.10+) | case "+": |
case _: | Everything else (like else) | case _: print("Wrong") |
exit(1) / exit() | Exit the program; 0 = success, 1 = error | Process finished with exit code 1 |
import sys / sys.argv[1] | Command-line arguments (strings) | python main.py 7 3 |
Python
operand:
:
result = number1 + number2
:
result = number1 - number2
_:
print()LoopsLesson 03.11.2026
| Command | What it does | Example |
|---|---|---|
for x in list: | Go through items one by one | for item in mylist: print(item) |
while condition: | Repeat while the condition is True | while len(mylist) > 0: |
while True: / break | Endless loop, leave with break | if answer == "q": break |
len(x) / .pop() | Length / remove and return the last item | len(["a", "b"]) → 2 |
Python
listlen = len(mylist)
listlen > 0:
listlen = listlen - 1 # decrease first, otherwise IndexError
print(mylist[listlen])String search, nested loopLesson 10.11.2026
| Command | What it does | Example |
|---|---|---|
.lower() / .upper() | Lower / upper case (new string) | "Mark".lower() → "mark" |
.find("m") | Index of first match, or -1 | "alma".find("m") → 2 |
.index("m") | Index; if missing — ValueError | "mark".index("m") → 0 |
"m" in s | Is the character/item there | "m" in "alma" → True |
break (nested) | Leaves only the inner loop | |
enumerate(x) | Index + value together | for i, c in enumerate(s): |
Python
name myList:
nameLower = name.lower()
nameLower.find() >= 0: # >= 0, not > 0: "Mark" has index 0
print( + name)Flag loop, continueLesson 10.11.2026
| Command | What it does | Example |
|---|---|---|
calc_on = True / while calc_on: | A flag controls the loop | calc_on = False # exit |
continue | Skip to the next iteration | after a wrong input |
Lists (list)Lesson 10.11.2026
| Command | What it does | Example |
|---|---|---|
[a, b, c] / list(x) | Create a list (types can be mixed) | ["Ori", 4, 5.6, True] |
x[1] / x[-1] | Item by index (from 0) / last | students[1] |
x[:2] / x[1:3] | Slice, end is excluded | ['Ori', 'Ilvia'] |
x[1][2] | Double index: item → character | "Ilvia"[2] → "v" |
.append(x) / .insert(i, x) | Add to end / before position i | students.insert(1, "Mark") |
.pop() / .pop(0) | Remove last / first | queue: pop(0) |
.remove(x) / del x[i] | Delete by value / by index |
Tuple, Set, DictionaryLesson 10.11.2026
| Command | What it does | Example |
|---|---|---|
(a, b, c) / tuple(x) | Tuple — immutable | tup = ("Yossi", "Yaniv", "Tomer") |
.index(x) / .count(x) | The only tuple methods | tup.index("Yaniv") → 1 |
{a, b} | Set — no duplicates, no order | {"Yossi", "Tomer", "Tomer"} → 2 items |
.add(x) / .discard(x) | Add / remove in a set | |
{"key": value} | Dictionary — key:value pairs | {"Yisrael": 24, "Mark": 36} |
d["key"] / d.get("key") | By key (missing — KeyError) / safe (missing — None) | ages["Yisrael"] → 24 |
d.items() | Pairs for a loop | for k, v in d.items(): |
Python
tup1 = list(tup) # tuple → list
tup1.insert(2, ) # change the list
tup = tuple(tup1) # list → tuple (not tuple(tup)!)Mutable / ImmutableLesson 10.11.2026
| Command | What it does | Example |
|---|---|---|
int, float, bool, str, tuple | Immutable — a change creates a new object | s[0] = "P" → TypeError |
list, dict, set | Mutable — the object itself changes | mylist.append(3) |
id(x) | Object address in memory | |
b = a / a.copy() | NOT a copy, a second name / a real copy |
OOP — overviewLesson 10.11.2026
| Command | What it does | Example |
|---|---|---|
class Human: | Class — a template: properties + methods | |
artem = Human("Artem", 25) | Object — an instance of a class | |
class Doctor(Human): | Inheritance: the child class gets everything from the parent |
FunctionsLesson 13.11.2026
| Command | What it does | Example |
|---|---|---|
def name(params): | Define a function | def calculate(num1, operand, num2): |
return x | Return a value and leave the function | return result |
return a, b, c | Return several values (tuple) | return num1, operand, num2 |
x, y, z = f() | Unpack the returned tuple | num1, operand, num2 = get_input() |
local / global | A variable inside a function exists only there | |
def f(x=0): | Default parameter |
Python
factorial(n):
result = 1
i range(2, n + 1):
result = result * i
result
print(factorial(4)) # 24Mistakes found in lessons
| Command | What happens | Fix |
|---|---|---|
int(input()) # user types abc | ValueError, the program crashes | .isdigit() / try-except |
if ... if ... # no else | result not created → NameError or an old value | elif + else |
5 / 0 | ZeroDivisionError | if num2 == 0: |
mylist[len(mylist)] | IndexError — the last index is len-1 | mylist[len(mylist) - 1] |
exit(1) # inside the calculator loop | One mistake closes the whole program | continue |
tup = tuple(tup) | The tuple did not change | tup = tuple(tup1) |
number2 = int(num2) | num2 stays a string: 12 * "45" repeats text | num2 = int(num2) |
continue # inside a function | SyntaxError — no loop around | return |
return str(a, b, c, d, e) | TypeError: str() takes at most 3 arguments | return f"{a} {b} {c}" |
def f(num1): print(number1) | Variable not found — different names | one name everywhere |
.find("m") > 0 | Misses a match at index 0 | .find("m") >= 0 |
Check yourself
Correct: 0 / 121. What does input() return?
2. Why is elif better than separate ifs?
3. What does continue do?
4. "alma".find("x") = ?
5. Which collections are immutable?
6. How do you remove duplicates from a list?
7. students[1:3] — does it include index 3?
8. How do you return 3 values from a function?
9. Why does calc_on = False inside a function not stop the loop?
10. 4! = ?
11. Queue: which method takes the first customer?
12. What does exit code 0 mean?
