String Concatenation

3 min read ·

String concatenation in Python means joining two or more strings together to form a single string. It is commonly used to combine text, messages, and dynamic values in programs.

What Is String Concatenation?

String concatenation allows you to:
  • Combine multiple strings
  • Create meaningful messages
  • Build dynamic output
Python provides multiple ways to concatenate strings.
Definition

String concatenation is the process of joining strings together.


Using the + Operator

The most common way to concatenate strings is using the + operator.
Important

Both operands must be strings when using +.


Concatenating Multiple Strings

You can join more than two strings using the + operator.

Using Comma in print() (Not True Concatenation)

Using commas in print() places values side by side with a space.
Key Difference

Comma does not create a single string; it only formats output.


Concatenation Using f-Strings (Recommended)

f-strings provide a clean and modern way to combine strings and variables.
Best Practice

f-strings are the best and safest way to concatenate strings.


Using format() Method

The format() method is another way to concatenate strings.

Repeating Strings (* Operator)

You can repeat strings using the * operator.

Common Errors in String Concatenation

Mixing String and Number with +

Correct Way


Exercise

  • Concatenate your first and last name
  • Print a sentence using f-string
  • Repeat a word three times