Numbers & Operators Interview Questions & Answers

6 questions Updated 2026-06-18

Python interview questions on int/float/complex, floor division and modulo with negatives, arbitrary precision, float precision, bitwise operators, and divmod.

Three: int (whole numbers, unlimited size), float (double-precision binary floating point), and complex (a real + imaginary part written with j). bool is technically a subclass of int (True == 1).

a = 42          # int
b = 3.14        # float
c = 2 + 3j      # complex
c.real, c.imag  # (2.0, 3.0)
True + True     # 2  — bool is an int subclass

Why it matters: mixing types promotes to the wider one (int + float -> float), and knowing the three types explains conversion and precision behavior.

/ is true division and always returns a float. // is floor division — it rounds toward negative infinity, not toward zero. % is the matching modulo, and in Python its result takes the sign of the divisor.

7 / 2       # 3.5    — always float
7 // 2      # 3
-7 // 2     # -4     — floors toward -infinity, not -3
-7 % 2      # 1      — sign follows the divisor (2)
7 % -2      # -1     — sign follows the divisor (-2)

The identity always holds: (a // b) * b + (a % b) == a. Rule of thumb: Python's floor/modulo differ from C/Java for negatives — expect non-negative % when the divisor is positive.

Python int has arbitrary precision — it grows to hold any value, limited only by available memory. There is no fixed 32/64-bit width, so computations never silently wrap around like in C or Java.

2 ** 100        # 1267650600228229401496703205376
x = 10 ** 1000  # a 1001-digit integer — no overflow
import sys
sys.maxsize     # largest "native" int, but ints can exceed it freely

Why it matters: you can compute huge factorials or cryptographic numbers directly, but very large ints cost more memory and arithmetic gets slower. Rule of thumb: integer overflow is simply not a concern in Python.

Floats are stored in binary (IEEE 754), and values like 0.1 and 0.2 have no exact binary representation — so tiny rounding errors accumulate. This is inherent to binary floating point, not a Python bug.

0.1 + 0.2            # 0.30000000000000004
0.1 + 0.2 == 0.3     # False
round(0.1 + 0.2, 2)  # 0.3   — round for display
import math
math.isclose(0.1 + 0.2, 0.3)   # True — tolerant comparison

from decimal import Decimal
Decimal("0.1") + Decimal("0.2")   # Decimal('0.3')  — exact

Rule of thumb: never compare floats with ==; use math.isclose or round, and reach for Decimal when you need exact decimal arithmetic (e.g. money).

Bitwise operators work on the binary representation of integers: & (and), | (or), ^ (xor), ~ (not/invert), << (left shift), and >> (right shift). Shifting left by n multiplies by 2**n.

5 & 3    # 1   (0b101 & 0b011)
5 | 3    # 7   (0b111)
5 ^ 3    # 6   (0b110)
~5       # -6  (~x == -(x+1))
1 << 4   # 16  (1 * 2**4)
20 >> 2  # 5   (20 // 4)

Why it matters: bitwise ops power flags/bitmasks, fast power-of-two math, and low-level protocols. Rule of thumb: ~x equals -(x + 1) because of two's complement.

divmod(a, b) returns the quotient and remainder as a single tuple (a // b, a % b) in one call. ** is exponentiation; with a third argument, the built-in pow(base, exp, mod) does efficient modular exponentiation.

divmod(17, 5)     # (3, 2)  — quotient and remainder together
2 ** 10           # 1024
pow(2, 10)        # 1024  — same as **
pow(2, 10, 1000)  # 24    — (2**10) % 1000, computed efficiently

Rule of thumb: use divmod when you need both results (e.g. converting seconds to minutes/seconds), and pow(a, b, m) for modular math instead of (a ** b) % m.

Practice tests are coming soon

Get notified when interactive mock interviews and quizzes launch.