The quiz where the difficulty automagically adapts to the player's Python knowledge
This is a question page. You can use this page to bookmark a question. Start a new quiz!
Question #881
my_list = ["apple", "banana", "grapefruit"]
id1 = id(my_list)
my_list+= ["cherries"]
id2 = id(my_list)
print(id1 == id2)
Lists are mutable. As such, the += operator applied on a list doesn't return a new object. The list my_list is appended in place. (stackoverflow.com/questions/2347265/why-does-behave-unexp...)
What is the output of the code snippet below?
— The Python Quiz (@thepythonquiz) April 9, 2021
my_list = ["apple", "banana", "grapefruit"]
id1 = id(my_list)
my_list+= ["cherries"]
id2 = id(my_list)
print(id1 == id2)
True
False
π Comment the answer, like and retweet! #python
Question difficulty: π΅π΅π΅π΅π΅