Python · Math, random & Decimal

What does this print? ``` import math nan = math.nan print(nan == nan) print(math.isnan(nan)) ```

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Math, random & Decimal

What does this print? ``` print(round(0.5), round(2.5)) print(round(1.5), round(3.5)) ```
You need to round prices half-up (2.5 -> 3, never 2). Why won't built-in round() do it, and what does?
What is the difference in result and return type between math.floor(-2.5), math.trunc(-2.5), and math.ceil(-2.5)?
You compare two values near zero with math.isclose(a, 0.0). Why might it return False even when a is tiny, and how do you fix it?
What does this print? ``` from decimal import Decimal print(Decimal("0.1") + Decimal("0.2")) ```
What does this print, and what's the bug? ``` from decimal import Decimal print(Decimal(0.1)) ```

Start learning today

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

Get it on App StoreGet it on Google Play