Python Numbers — Python Technical Interview Questions & Answers
Python Numbers
Python Numbers
- Numbers in Python are int, float, and complex. int has no fixed 32-bit cap — 10**20 is still an int. float is decimal, but binary floating point is approximate: 0.1 + 0.2 is not exactly 0.3. complex uses a+bj for science work; freshers rarely need it on day one.
- Cast with int("5"), float(3). int("Asha") raises ValueError. Interview: int is unlimited precision; float has precision limits. Don’t claim float is “exact money” — use Decimal later if they push.
- Python Numbers — output: 32, 3.5, 3. Power, true divide, floor divide.
Technical Interview Tip: int vs float with one precision caveat.
Code Examples for Python Numbers
Example
# Numbers
print(2 ** 5)
print(7 / 2)
print(7 // 2)
Python Numbers — output: 32, 3.5, 3. Power, true divide, floor divide.
How to Explain Python Numbers to an Interviewer
Explain Numbers as if you are teaching a junior — definition, then one tiny script.
int / float / complex. int can be huge.
What does the example print, and why?
Python Numbers — output: 32, 3
What mistake do freshers make with Numbers?
0.1 + 0.2 exact float.