Operators + and *
The addition operator "
+" serves to
join (
concatenate) two or more strings.
For two numeric values, the "
*" operator represents multiplication. In the case of
str operands, it serves to
multiply the value (the text).
EXAMPLE
Editor - lesson_8_strings.py
|
|
DETAILS
We won't dwell on this aspect too much. Simply put, the "
+" operator joins the strings as a result of the operation.
We can play with spaces (the
blank character), with multiple strings, try it out!
Be mindful of the data type:
Both must be of type
str, otherwise you will get an error.
The variable
n holds an
int object, while
m holds a
str object. Use the conversion
str(n)+m!
Run the program then proceed to the next page.