Why can’t I .append( ) each word to the result?


#1

Question

Why can’t I .append( ) each word to the result?

Answer

The usage of the word “append” in these instructions means literally appending some word to the result string, not to be confused with the .append() function available to lists.
We can append something to a string by taking its current value and adding to it the string we want to be at the end! This is possible using the += operator, which is used as:
my_variable += some_value
It takes the existing value of the variable and adds on to it.


FAQ: Learn Python - Lists and Functions - Using strings in lists in functions