Concatenation
To add two strings together you must use concatenation. Concatenation allows you to combine multiple strings (and integers and floats!) into one variable.
Key Points
Concatenation is done by adding two strings together.
You can also add integers and floats to make a string.
Concatenation doesn’t add spaces after strings or variables.
Simple Concatenation
When you perform an addition on two strings, it adds the two strings together.
The output of the following code will be “JohnSmith“.
name = "John" + "Smith" print(name)
You can also concatenate variables together.
first = "John" second = "Smith" name = first + second print(name)
Complex Concatenation
You can also combine integers and floats together with strings to make complex strings.
To do this you must parse the other data types as a string.
The output of the following code is “John is 35 years old.“
name = "John" age = 35 fact = name + " is " + str(age) + " years old." print(fact)