How to Add Letters to a String in Python

To add letters to a string in Python, you can use string concatenation or string formatting.

The following examples show how to add letters to a string in Python.

Using String Concatenation

We can use string concatenation to add letters to a string using the + operator.

Suppose we have the following strings:

# Declare strings
string1 = "Hello"
string2 = " World"

# Add strings
result_string = string1 + string2

# Show added string
print(result_string)

Output: 👇️

Hello World

In this example, we use the + operator to concatenate string1 and string2.

Using String Formatting

We can use string formatting to add letters to a string using the format() function.

Suppose we have the following string:

# Declare string
string1 = "My name is {} and I am {} years old.".format("John", 25)

# Show string
print(string1)

Output: 👇️

My name is John and I am 25 years old.

In this example, we use the format() function to add the name John and the age 25 to the string.