I am a bit do not understand the principle of the addition of lists and strings in Python.
For example, we have a list:
students = ['Ivan', 'Michael', 'Olga']
The result of the expression:
students += 'John'
will be:
['Ivan', 'Michael', 'Olga', 'J', 'o', 'h', 'n']
And in this case, string 'John' will be processed as a list and every symbol will be added to list students
.
But why the processing of expression:
students = students + 'John'
occurs otherwise? In this case, we just get an error.
I always thought that expressions a += b
and a = a + b
are equivalent.
But why here in one case the string is expanded to the list, and in the other case this does not happen and we get an error?