strings are immutable (unchangeable). But you can index and join items.

mystring = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
mystring = 'ABCDE'.join([mystring[:20],mystring[24:]])

'XXXXXXXXXXXXXXXXXXXXABCDEXXXXXXXXXXXXXX'

Do be careful as the string length "ABCDE" and the number of items you omit between mystring[:20], mystring[24:] need to be the same length.

Answer from Back2Basics on Stack Overflow
๐ŸŒ
STechies
stechies.com โ€บ stringreplace-python-3x
How to use string.replace() in Python
How to use string.replace() in python 3.x, In python replace() is an inbuilt function which returns a string by replacing sub-string with another sub-string, with all occurrences or specified numbers.
Discussions

how to substitute part of a string in python? - Stack Overflow
How to replace a set of characters inside another string in Python? Here is what I'm trying to do: let's say I have a string 'abcdefghijkl' and want to replace the 2-d from the end symbol (k) with... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - how do i replace a character in a string by range? - Stack Overflow
2 How do I replace characters in a string in Python? More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Replacing a character from a certain index - Stack Overflow
As strings are immutable in Python, just create a new string which includes the value at the desired index. Assuming you have a string s, perhaps s = "mystring" You can quickly (and obviously) replace a portion at a desired index by placing it between "slices" of the original. ... def replacer(s, newstring, index, nofail=False): # raise an error if index is outside of the string if not nofail and index not in range... More on stackoverflow.com
๐ŸŒ stackoverflow.com
August 25, 2020
How to sort IP Addresses in python
ips.sort(key=lambda s: map(int, s.split('.')))
More on reddit.com
๐ŸŒ r/Python
8
0
August 17, 2009
๐ŸŒ
Aspose
reference.aspose.com โ€บ api reference โ€บ words โ€บ python-net โ€บ aspose.words โ€บ range โ€บ replace
Range.replace method | Aspose.Words for Python
July 15, 2026 - Replaces all occurrences of a specified character string pattern with a replacement string. def replace(self, pattern: str, replacement: str): ... The pattern will not be used as regular expression.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_replace.asp
Python String replace() Method
Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The replace() method replaces a specified phrase with another specified phrase.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-replace-list-elements-within-a-range-with-a-given-number
Python Program to replace list elements within a range with a given number - GeeksforGeeks
July 23, 2025 - # initializing list test_list = [4, 6, 8, 1, 2, 9, 0, 10, 12, 3, 9, 1] # printing original list print("The original list is : " + str(test_list)) # initializing i, j i, j = 4, 8 # initializing K K = 9 # getting range using slicing and # required elements using * operator test_list[i:j] = [K] * (j - i) # printing result print("Range Updated list : " + str(test_list))
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-string-replace-character-at-specific-position
Python - Replace Character at Specific Index in String
The final string is 'pythonexamples'. ... You can replace multiple characters in a string at specified indices by looping through the indices.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ stdtypes.html
Built-in Types โ€” Python 3.14.7 documentation
The linspace recipe shows how to implement a lazy version of range suitable for floating-point applications. The following table summarizes the text and binary sequence types methods by category. Textual data in Python is handled with str objects, or strings.
Find elsewhere
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ replace-character-string-python
Python Replace Character in String | FavTutor
October 6, 2021 - Slicing is a method in python which ... lists, and tuples. Using slicing, you can return a range of characters by specifying the start index and end index separated by a colon and return the part of the string....
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-string-replace
Python String Replace Methods | Using replace() and More
August 19, 2024 - By understanding and using these alternative methods, you can handle a wider range of string replacement scenarios in Python.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-access-a-range-of-characters-from-a-string-in-Python
How to access a range of characters from a string in Python - Quora
Answer (1 of 3): Python โ€“ Extract range characters from String Given a String, extract characters only which lie between given letters. > Input : test_str = โ€˜geekforgeeks is bestโ€™, strt, end = โ€œgโ€, โ€œsโ€ Output : gkorgksiss Explanation : All characters after g and before s are retained.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ string_replace.htm
Python String replace() Method
September 23, 2020 - The Python String replace() method replaces all occurrences of one substring in a string with another substring. This method is used to create another string by replacing some parts of the original string, whose gist might remain unmodified.
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ python โ€บ python strings: replace, join, split, reverse, uppercase & lowercase
Python Strings: Replace, Join, Split, Reverse, Uppercase & Lowercase
August 12, 2024 - In slicing, if range is declared [1:5], it can actually fetch the value from range [1:4] You can update Python String by re-assigning a variable to another string ยท Method replace() returns a copy of the string in which the occurrence of old is replaced with new.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ replace-occurrences-of-a-substring-in-string-with-python
Replace Occurrences of a Substring in String with Python
September 21, 2020 - Python offers easy and simple functions for string handling. The easiest way to replace all occurrences of a given substring in a string is to use the replace() function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-string-replace
Python String replace() Method - GeeksforGeeks
October 28, 2024 - Returns a new string with the specified replacements made. The original string remains unchanged since strings in Python are immutable.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-replace-to-k-at-ith-index-in-string
Replace a String character at given index in Python - GeeksforGeeks
April 16, 2025 - Sometimes, while working with Python ... many domains. Let's discuss certain ways to solve this problem. Method #1 : Using replace() + enumerate() + loop This is...
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ string-replace-method
Master Python's String Replace Method for Text Manipulation
The default value (-1) replaces all occurrences. The syntax of this method ensures clarity and flexibility, allowing developers to easily modify strings without altering the original data. In the Python programming languages, replace() is useful for replacing characters and other substrings within strings.