How to concatenate (combine) multiple strings in Python

String Concatenation in Python?

In Python, string concatenation is the process of combining two or more strings into a single string.

Concatenating strings using addition ('+') operator

In Python, you can concatenate (combine) two or multiple strings using '+' operator.

In the following example, the string variables first_name, and last_name are combined into a single string using '+' operator. Combined string value is passed to the string variable fullname fullname = first_name + " " +last_name.

Note: Space (" ") is used to keep space between first_name and last_name.

Please take a closer look at the following example:

Example of using ('+') operator to combine strings

Output of the above example
John Smith

Concatenating strings using addition & assignment ('+=') operator

In Python, you can concatenate (combine) two or multiple strings using '+=' operator.

In the following example, the string variable my_string has the string value "Python is ". We can add more string data to the variable just using the '+=' operator.

my_string += "fun." is used to add the text "fun." to the existing string value ("Python is ") of the 'my_string' variable.

Please take a closer look at the following example:

Example of using ('+=') operator to combine strings

Output of the above example
Python is fun.

Live Code Playground

In the following Python code editor, you can practice the above code by concatenating more strings. Click on the 'Execute Code' button to execute the code; the executed output will be displayed in the following Python Code Output frame. Practice until you become comfortable and proficient with your code.

Python logo Python Online Editor
Python Code Output