Why the string breaks while adding the lists? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

19th Apr 2021, 5:52 AM
Aman Kumar
Aman Kumar - avatar
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.
19th Apr 2021, 5:58 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 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>.
19th Apr 2021, 6:21 AM
Ipang
+ 2
I am still confused
19th Apr 2021, 6:25 AM
Aman Kumar
Aman Kumar - avatar
+ 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.
19th Apr 2021, 6:40 AM
Ipang