+ 5
List += âabcâ (python)
Hi everyone, Can anybody explain me why: List = [] List += âabcâ Print (list) Output: [a,b,c] Why output come as separate letters, and not as whole string? Thanks,
4 Answers
+ 8
To just add "abc" as is try :
List.append("abc")
+ 3
If you want a whole string, start with:
List = ââ
instead of:
List = []
Then youâll be working with a string. You might want to reconsider the name of the variable then :P
+ 1
Thanks guys
- 1
In most languages, strings are just an array of chars all mushed together into a data type known as a string. Because you're adding the string to the list, it's basically the same as adding two lists together, resulting in all of the elements in the lists to all be put together into one whole list.
Hope this helped!