Interview Q&A / Python
Python interview questions
Lists, dictionaries, generators, decorators and the Python questions asked in service-company and data roles.
Prefer rapid revision? Practise Python short interview answers →
- What is the difference between /, // and % in Python, especially with negative numbers?
/ is true division and always returns a float. // is floor division: it rounds down toward negative infinity. % returns the remainder that matches floor division, so the result takes the sign of the divisor. For example -7 // 2 is -4 and -7 % 2 is 1.
BeginnerQuick answer1 min read - What is the difference between is and == in Python?
== checks whether two objects have equal values, using __eq__. is checks whether two names point to the very same object in memory, by comparing identity. Use is only for singletons like None.
BeginnerQuick answer1 min read