How to duplicate characters in a string?

Let’s say I have this string:


How can I transform it into:


@jaccobtw, you can’t do it, since, in Python, strings are immutable, meaning that they cannot be changed.

However, you can make a new string, by using the + operator. It works with strings by joining strings together, a process called concatenation.

my_str = "ac"
my_new_str = my_str + "c"



ac   # original string unchanged
acc  # new string