Python · The Data Model: Identity & Mutability

Predict the output: ``` number1 = 1987.0 number2 = 1987 print(number1 == number2) print(type(number1) == type(number2)) ```

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 The Data Model: Identity & Mutability

Predict the output: ``` v1 = [1, 2, 3] v2 = v1 v3 = [1, 2, 3] print(v1 == v3, v1 is v3) print(v1 == v2, v1 is v2) ```
Every non-speed: a colleague checks if x is 1000: and it returns False even though x == 1000. What's the rule that explains both this and why x is 256 sometimes 'works'?
Does assignment b = a copy the object that a refers to?
Predict the output: ``` a = "water " b = a a += "bottle" print(a) print(b) ```
Predict the output: ``` a = [1, 2] b = a a += [3, 4] print(a) print(b) ```
Why does the SAME += line leave an aliased str untouched but mutate an aliased list?

Start learning today

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

Get it on App StoreGet it on Google Play