+ 3

What is the difference between the following two operations in Python?

lst = [1, 2] lst = lst + [3] and lst = [1, 2] lst.append(3)

29th Apr 2021, 5:16 PM
Suhayl Qodirov
Suhayl Qodirov - avatar
1 Odpowiedź
+ 5
You append an element but you add a list. An element can be everything also another list, But the operator + of a list is only defined for another list. in your case the result is the same
29th Apr 2021, 5:23 PM
Oma Falk
Oma Falk - avatar