0

I have this doubt.

colors=["red","green"] colors.extend("blue") print(colors) Output is = ['red','green','b','l','u','e'] Why the blue is appended like this why it's not 'blue'

13th Dec 2019, 6:35 AM
parag sahu
parag sahu - avatar
2 Answers
+ 2
extend expects an iterable argument . when you pass it a string, it iterates over it and returns each char at a time. if it were colors.extend(["blue"]) it would output what you expected.
13th Dec 2019, 6:45 AM
Bahha┣
Bahha┣ - avatar
+ 1
bahha🐧 Thanks bro. I got it.
13th Dec 2019, 6:47 AM
parag sahu
parag sahu - avatar