IAE Academy

Python formulas

Programming in Python. 4 formulas for GATE CS, DA Data Structures and Algorithms, each with when to use it. Each is explained in the topic notes.

All 4 Python formulas

FLOOR DIVISION AND REMAINDER IN PYTHON

Holds for integers with b nonzero; a // b is the floor of the true quotient, so a nonzero remainder takes the sign of b.

NUMBER OF VALUES IN A RANGE

Holds for integers a, b and any nonzero step k, positive or negative; for example len(range(3, 20, 4)) = ceil(17/4) = 5 and len(range(5, 0, -2)) = ceil(2.5) = 3.

SET OPERATION SIZES

For finite sets; A △ B is the symmetric difference, written A ^ B in Python. Use these to count len(A | B) or len(A ^ B) without listing the elements.

NUMBER OF CALLS MADE BY NAIVE FIBONACCI RECURSION

For the fib above, which returns directly for n < 2 and otherwise calls itself on n-1 and n-2, with F(0)=0, F(1)=1. C(n) counts every call, the first one included; for example fib(6) makes C(6) = 2·13 − 1 = 25 calls.

Where this was asked: 2024 (3), 2025 (3), 2026 (4). See the 10 previous-year questions on Python. This shows what was asked, not what will be asked.