Question #878

What is the output of the code snippet below?
some_fruits = ["banana", "apple", "pear"]
some_fruits += "grapefruit"
print(some_fruits)

The += operator will append all elements of "grapefruit" to the list some_fruits . As "grapefruit" is a string, every letter is an element. The result is then ['banana', 'apple', 'pear', 'g', 'r', 'a', 'p', 'e', 'f', 'r', 'u', 'i', 't'] . (geeksforgeeks.org/python-append-string-to-list)


Comment on Disqus:

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