How to concatenate strings?

QuestionsQuestions4 SkillsProPython Control StructuresOct, 23 2025
0136

In Python, you can concatenate strings using several methods. Here are the most common ways:

1. Using the + Operator

You can simply use the + operator to concatenate two or more strings.

string1 = "Hello"
string2 = "World"
combined = string1 + " " + string2
print(combined)  # Output: Hello World

2. Using the join() Method

The join() method is useful for concatenating a list of strings.

strings = ["Hello", "World"]
combined = " ".join(strings)
print(combined)  # Output: Hello World

3. Using F-strings (Python 3.6+)

F-strings allow you to embed expressions inside string literals.

string1 = "Hello"
string2 = "World"
combined = f"{string1} {string2}"
print(combined)  # Output: Hello World

4. Using the format() Method

You can also use the format() method for string formatting.

string1 = "Hello"
string2 = "World"
combined = "{} {}".format(string1, string2)
print(combined)  # Output: Hello World

These methods provide flexibility depending on your needs. Choose the one that best fits your use case!

0 Comments

no data
Be the first to share your comment!