0

Adding a string to a list

Hi, Why is the output a list of letters instead of ["Python"]? a =[] a+="Python" print (a)

26th Jun 2019, 4:48 AM
Marek Kluczewski
Marek Kluczewski - avatar
2 odpowiedzi
+ 4
If you want to use +=, write a += ["Python"]
26th Jun 2019, 4:58 AM
Anna
Anna - avatar
+ 2
Because you don't add elements to the list with a plus sign, you should use the append method: a = [] a.append("Python") print(a)
26th Jun 2019, 4:51 AM
Airree
Airree - avatar