Python

Numbers: int, float, bool, complex

39 flashcards · answers and spaced-repetition review in the KnowCard app

What does this print? ``` print(5 & 3) print(5 | 2) print(5 ^ 1) ```
What does this print? ``` print(~9) ```
What does this print? ``` print(1 << 4) print(20 >> 2) ```
What does this print? ``` c = 3 + 4j print(c.real, c.imag) print(type(c.real)) ```
What does this print? ``` a = 1 + 2j b = 1 + 3j print(a == b) print(a < b) ```
What does this print? ``` print(6 / 2) print(7 // 2) ```
What does this print? ``` print(-7 // 2) ```
What does this print? ``` print(-7 % 3) print(7 % -3) ```
What does this print? ``` print(2 ** 3 ** 2) ```
Does Python's int overflow for very large values like a 64-bit C int does?
What does this print? ``` print(0.1 + 0.2 == 0.3) ```
How do you get a float with the value infinity, given that inf is not a usable constant?
What does this print? ``` nan = float("nan") print(nan == nan) ```
What does this print? ``` print(True + True) print(isinstance(True, int)) ```
What does this print? ``` print(0 or "hello") print("a" and "b") ```
What does this print? ``` x = True if x or print("side"): print("done") ```
Are these two empty-check expressions equivalent for a list? ``` if len(items) > 0: ... if items: ... ```
What does this print? ``` x = 5 print(1 < x < 10) print(10 < x < 20) ```
What does this print? ``` print(0xFF) print(0o17) print(0b1010) ```
What does this print? ``` print(int("ff", 16)) print(int("54425", 6)) ```
In the augmented assignment x += y, what may x and y each be, and what does it expand to?
What does this print, or does it fail? print(int(33.9)) print(int(1 + 2j))
Since Python 3.6, what do underscores do in a numeric literal like 1_000_000 or 3.000_000_1?
What does (37).bit_length() return, and why are the parentheses around 37 needed?
Does Python's built-in float offer a single-precision (32-bit) option?
What does this print? print(1.5e3) print(2E-3)
Which of these are valid float literals: -3., .001, 3,14?
What does this print? print(1987 == 1987.0) print(1234 == "1234")
How can you check whether a float holds a whole-number value (e.g. tell 5.0 apart from 5.5)?
Are Python's numeric types (int, float, bool, complex) mutable or immutable, and what follows from that for x += 1?
Does Python have ++ and -- increment/decrement operators like C? What do you use instead?
What does this print? print(abs(-12.34)) print(abs(3 + 4j))
Python has and and or as logical operators — is there also a logical xor?
What does this print, or does it fail? print(complex(1, 3)) print(complex("3+4j")) print(complex("3 + 4j"))
What does float() (no argument) return, and can you call float(3 + 4j)?
What is the advantage of pow(x, y, z) over writing x ** y % z?
What does this print? print(round(2.5)) print(round(3.14159, 2))
Why does math.sqrt(-1) fail, and which module handles complex numbers?
What does this print, and why? from decimal import Decimal print(Decimal(0.7) == 0.7) print(Decimal("0.7") == 0.7)

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play