+ 2
Why the append and concatenation (+) works differently for strings in list?
s=[1,2,3] s.append("text1") s+="text2" print(s) [1, 2, 3, 'text1', 't', 'e', 'x', 't', '2'] rather than [1,2,3,'text1,'text2']
1 ответ
+ 1
For list, Python is actually doing same thing behind the hood (appending)
When you do
s += "text2" it's short form of
for j in "text2":
s.append(j)
Thus,
If s = [ ]
s+="abcd" will give different result as s.append("abcd")