String Concatenation in Python

By Hemanta Sundaray on 2021-09-06

In Python, we can combine literal strings or string variables using the + operator.

firstName = "Hemanta"

lastName = "Sundaray"

print(firstName + " " + lastName)
# Hemanta Sundaray

print("Hemanta " + "Sundaray")
# Hemanta Sundaray

We can also combine literal strings (not string variables) just by having one after the other:

print("Hemanta " "Sundaray")
# Hemanta Sundaray

If we are trying to print() a numeric variable, we can use commas to pass it as a different argument rather than converting it to a string.

age_string_one = "I am"

age = 32

age_string_two = "years old."

print(age_string_one, age, age_string_two)
# I am 32 years old.

Join the Newsletter