Question #913

What is the output of the code snippet below?
my_list = [None, None]
my_list[2:] = [True]
print(my_list)

Another Python syntactic sugar! First, my_list[2:] accesses the list after the 2nd element, e.g. after the second None . Because my_list[2:] represents all elements between the second None and the end of the list, updating this area with another list will be equivalend to the append() method. (programiz.com/python-programming/methods/list/append)


Comment on Disqus:

Question difficulty: ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต