Variables, Types & Operators · Question 15 · Medium
Which statement about the operators == and is is correct?
- == compares the values of two objects, while is checks whether both names refer to the same object
- is compares the values of two objects, while == checks whether both names refer to the same object
- Both give the same result for any two lists that have equal contents
- is can be used only with numbers, while == works with every type
Answer and explanation
Answer: A. == compares the values of two objects, while is checks whether both names refer to the same object
Explanation: == asks whether two objects are equal in value; is asks whether they are one and the same object in memory. Two separately built lists with equal contents are == but not is.
Previous: A string holding a decimal number is passed straight to int(). What is the… · Next: Booleans are used in arithmetic here. What does the snippet print?
Practise variables, types & operators
Try a fresh set of variables, types & operators questions with an explanation after every answer, free and without signing up: Variables, Types & Operators practice. Or sit a full placement mock test.
More variables, types & operators questions
- Two separate lists hold the same values and a third name points to the first…
- Python 3's round() is called on two values that end in .5. What does this print?
- A string holding a decimal number is passed straight to int(). What is the…
- Booleans are used in arithmetic here. What does the snippet print?
- Floor division by a float and a remainder with a negative divisor are printed…
- Five different operators appear in one expression. Following precedence rules…
- A float product is compared with 0.3 in two ways. What does this print?
- Three type conversions are printed on one line. What is the output?
More python practice
Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge