+ 1
Why the string breaks while adding the lists?
There are three codes. In first case the string breaks, in second case I am getting 'none' and for the third please see and run the code. https://code.sololearn.com/cxEzhE2L0d50/?ref=app
4 Answers
+ 4
`list.extend (iterable)` goes through `iterable` and appends every value in it to the end of the `list`. But it does not return any value, so it is defaulted to None.
+ 3
fruit = ("apple") # a string
fruit = ("apple",) # a tuple with one string. Notice the comma
If you extend <car> by <fruit>, where <fruit> is a string, you append the characters from the string into <car>.
If you extend <car> by <fruit>, where <fruit> is a tuple, you append the contents of the tuple into <car>.
+ 2
I am still confused
+ 2
Try to change the value for <fruit>, from ("apple") to ("apple",) and run the code again. You will notice the difference.
But this time print <car> rather than <s> in the second code example.