I am not sure what you want to achive, but it seems you just want to replace a '1' for an 'I' just once, so try this:

string = "11234"
string.replace('1', 'I', 1)

str.replace takes 3 parameters old, new, and count (which is optional). count indicates the number of times you want to replace the old substring with the new substring.

Answer from lmiguelvargasf on Stack Overflow
Discussions

python - How to replace the first two characters of a string, with the first two characters of another string? - Stack Overflow
I'm aware that this replacing characters question may have already been posed and I've checked them out, but they still don't answer my question. I'm also new to python, so my understand isn't all ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to find the first character of a string and replace all findings of it in the same string in Python? - Stack Overflow
I'm trying to create a method that brings in a string, looks for the first letter of the string and then replaces all occurrences of that letter with another character. It obviously does not work ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python: How can I replace one specific character on a string while leaving the rest of the string as it was?
str.replace replaces all instances of the search string with the replacement string, which isn't what you want the correct solution would be to turn the string into a list, update the value at the wanted index and then "".join(char_list) to rebuild the string More on reddit.com
๐ŸŒ r/learnprogramming
12
6
October 18, 2023
Pattern to match first occurrence in line?
The easiest would be to match from the beginning of the line lazily: ^.\{-}foo This will stop at the first occurrence of foo. To skip the leading stuff and just keep foo itself as the match, use \zs: ^.\{-}\zsfoo If the search needs to be more robust, use a negative look-behind. Warning: The syntax will make your eyes bleed. ^\(\(foo\)\@ More on reddit.com
๐ŸŒ r/vim
6
15
May 20, 2012
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ python replace the first character in string | example code
Python replace the first character in string | Example code
June 8, 2023 - How to change characters in string Python. Use the list() and join the function. s = "Hello World!" new = list(s) new[0] = 'Y' print(''.join(new)) Output: Yello World! Or you can utilize string slicing and concatenation.
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-21391.html
Replace first character
Really having a hard time figuring this out. What I'm trying to do is every time the user inputs text, it will modify and replace every leading character with a '#'. For example the user types: Hello my name is bob, python would print '#ello #y #ame ...
๐ŸŒ
Quora
quora.com โ€บ How-do-you-replace-the-first-two-characters-of-a-string-in-Python
How to replace the first two characters of a string in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
๐ŸŒ
StrataScratch
stratascratch.com โ€บ blog โ€บ how-to-replace-a-character-in-a-python-string
How to Replace a Character in a Python String - StrataScratch
October 18, 2024 - The basic method for replacing a string in Python is intuitively named str.replace(). It allows you to specify one character or a whole substring you want to replace and a character (or a substring) you want to replace it with.
Find elsewhere
๐ŸŒ
ItSolutionstuff
itsolutionstuff.com โ€บ post โ€บ python-replace-first-character-occurrence-in-string-exampleexample.html
Python Replace First Character Occurrence in String Example - ItSolutionstuff.com
October 30, 2023 - In this example, i will add myString variable with hello string. Then we will use replace() function to replace first character occurrence from string in python.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ replace a character in a string python
Replace a Character in a String Python - Scaler Topics
April 20, 2024 - One of the most widely used ways is using the Python built-in method string.replace(). The .replace() method replaces the old character with a new character. We can also use loops to replace a character in a string in Python. The string slicing method can also be used to replace a string in python.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-string-replace-how-to-replace-a-character-in-a-string
Python string.replace() โ€“ How to Replace a Character in a String
September 1, 2022 - The new_char argument is the set of characters that replaces the old_char. The count argument, which is optional, specifies how many occurrences will be replaced. If this is not specified, all occurrences of the old_char will be replaced with the new_char. Let's see some examples. Here's an example that replaces "JavaScript" with "PHP" in a string: str = "I love JavaScript. I prefer JavaScript to Python because JavaScript looks more beautiful" new_str = str.replace("JavaScript", "PHP") print(new_str) # I love PHP.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-replace-occurrences-by-k-except-first-character
Python โ€“ Replace occurrences by K except first character | GeeksforGeeks
April 18, 2023 - If the character is equal to the first character and it is not the first occurrence, then replace it with the new character K, else keep the original character. Also, add the first character of the input string as it is in the beginning.
๐ŸŒ
Tutorial Reference
tutorialreference.com โ€บ python โ€บ examples โ€บ faq โ€บ python-how-to-replace-first-n-characters-in-a-string
How to Replace First N Characters in Python Strings | Tutorial Reference
my_str[n:] creates a slice starting from index n (the character after the ones you want to replace) to the end of the string. The + operator concatenates your replacement_prefix with the rest of the original string. If the replacement value isn't a string, convert it first using str().
๐ŸŒ
Esri Community
community.esri.com โ€บ t5 โ€บ arcgis-pro-questions โ€บ how-do-i-replace-the-first-character-of-a-string โ€บ td-p โ€บ 731955
How do I replace the first character of a string using calculate field in ArcGIS Pro?
July 29, 2020 - I have a field, FACILITY ID, that is populated as string values as 00001,00002, 00003, and so on. All values in the field are 5 characters long. I want to change the first number in to a 1 so the values of the field look like 10001, 10002, 10003, etc. I'm pretty sure i should use the .replace(), but I cannot format it correctly. Any advice would be very welcome. Thank you. Solved! Go to Solution. ... It is best to do calculations in a new field in case things go real bad.
๐ŸŒ
Dirask
dirask.com โ€บ posts โ€บ Python-replace-first-3-characters-in-string-j8g65p
Python - replace first 3 characters in string
You need to set it to 1, so you won't replace anything but the first occurrence of the substring. ... text = "ABCD ABCD ABCD" replacement = "XYZ" result = text.replace(text[0:3], replacement, 1) print("Before: ", text) # ABCD ABCD ABCD print("After: ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 38116270 โ€บ how-to-find-the-first-character-of-a-string-and-replace-all-findings-of-it-in-th
How to find the first character of a string and replace all findings of it in the same string in Python? - Stack Overflow
I'm trying to create a method that brings in a string, looks for the first letter of the string and then replaces all occurrences of that letter with another character. It obviously does not work to use s[letter] to the new character, since letter in this case is not an index. But what solution should be used instead? Copydef fix_start(s): letterToReplace = s[0] for letter in s: if letter is letterToReplace: s[letter] = '*' return s ... Note that you can't modify a string in python, therefore the resulting string will not be the same string.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ python-program-to-replace-occurrences-by-k-except-first-character
Python Program to Replace occurrences by K except first character
This approach slices the string from the second character and replaces all occurrences of the first character, then concatenates with the original first character ? ... # input string inputString = 'blueforblueforblue' print("Input string:", inputString) # replacement character k = '*' # replace all occurrences except first character resultantStr = inputString[0] + inputString[1:].replace(inputString[0], k) print("Resultant string after replacing:", resultantStr)
๐ŸŒ
Quora
quora.com โ€บ How-do-you-change-one-character-in-a-string-in-Python
How to change one character in a string in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
๐ŸŒ
Python Guides
pythonguides.com โ€บ remove-first-character-from-a-string-in-python
Remove the First Character of a Python String
August 20, 2025 - Use replace() if the first character also appears later in the string. Use regex if youโ€™re already cleaning text with patterns. Use a loop only for learning purposes. For most cases, I stick to slicing because itโ€™s short, fast, and easy to read. When I first started working with Python ...