As a developer working on various projects across the USA, In one of my projects, I came across a scenario where I needed to insert a character into a string at a specific index in Python, which made to explore more about this topic. After researching I found three effective ways to accomplish this task. In this tutorial, I will explain all the methods with suitable examples.
Insert a Character into a String at a Specific Index in Python
Let us learn all three important methods to insert a character into a string at a specific index in Python.
Read How to Create a String of N Characters in Python?
Method 1: Use String Slicing and Concatenation
One way to add a character at a specified position in a Python string is by using string slicing and concatenation. Here’s an example:
def insert_char(string, char, index):
return string[:index] + char + string[index:]
# Example usage
name = "John Doe"
modified_name = insert_char(name, "Q", 5)
print(modified_name) Output:
John QDoeIn the screenshot below you can see the executed example code with the output

The insert_char function inserts a character into a string at a specified index. It does this by splitting the string into two parts: before and after the index. Then, it combines these parts with the character in between.
Check out How to Split a String into Equal Parts in Python?
Method 2: Use List Manipulation
Another approach to inserting a character into a Python string at a certain index is by converting the string to a list, modifying the list, and then converting it back to a string. Here’s an example:
def insert_char(string, char, index):
string_list = list(string)
string_list.insert(index, char)
return ''.join(string_list)
# Example usage
city = "New York"
modified_city = insert_char(city, "X", 4)
print(modified_city) Output:
New XYorkIn the screenshot below you can see the executed example code with the output

In this method, we first convert the string to a list using the list() function. Then, we use the insert() method of the list to insert the character at the specified index. Finally, we use the join() method to convert the modified list back into a string.
Read How to Insert a Python Variable into a String?
Method 3: Use f-strings
If you are using Python 3.6 or higher, you can leverage the power of f-strings to add a substring at a specific index. Here’s an example:
def insert_char(string, char, index):
return f"{string[:index]}{char}{string[index:]}"
# Example usage
state = "California"
modified_state = insert_char(state, "Z", 7)
print(modified_state)Output:
CaliforZniaIn the screenshot below you can see the executed example code with the output

In this method, we use an f-string to create the modified string. Inside the f-string, we use string slicing similar to Method 1, but we directly insert the character {char} within the f-string.
Check out How to Split a String by Index in Python?
Conclusion
In this tutorial, I have helped you learn how to insert a character into a string at a specific index in Python. We have discussed methods like using string slicing and concatenation, list manipulation, and the use of f-string.
You may also read:
- Convert Binary to Decimal in Python
- How to Split a String Every N Characters in Python?
- Python Split Regex

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.