Can I concatenate and append the result in a single statement?


#1

Question

In the context of this exercise, can I concatenate two strings and append the result in a single statement?

Answer

Yes, you can!

Generally, in Python and most other programming languages, you can call methods or functions with an input value which is an expression, such as 1 + 1. However, the expressions must be so that they evaluate to some result; here 1 + 1 will evaluate to 2. The expression will be evaluated first, then the method is run on the evaluated result.

Because of this, we can concatenate two strings, which is an expression, and append the result to a list, all in the same statement. The general structure of the syntax will look similar to this:

list.method(expression)