For an empty Python list, there are a number of things to add later, two of which are adding content directly with "+" and the other is Listname.append (x) to add content
Where, if the string is processed
When using "+", the string is split into list elements, added to the list, and append is used to package the string into an element and add it to the list.
For example, if you use append:
all = []
Print "\nenter lines ('. ' by itself to quit). \ n"
While True:
Entry = Raw_input (">")
If entry = = '. ':
All.append (".")
Break
Else
Print all
Print "done!"
Assuming the input to the content is Hello, world, then the result is:
Enter lines ('. ' by itself to quit).
>hello
>world
.
[' Hello ', ' world ', '. ']
done!
If you are using "+":
all = []
Print "\nenter lines ('. ' by itself to quit). \ n"
While True:
Entry = Raw_input (">")
If entry = = '. ':
All.append (".")
Break
Else
all+= (Entry)
Print all
Print "done!"
Then the output is:
Enter lines ('. ' by itself to quit).
>hello
>world
.
[' H ', ' e ', ' l ', ' l ', ' o ', ' w ', ' O ', ' r ', ' L ', ' d ', '. ']
done!
The difference between Python's "+" and append when adding strings