About 2,870,000 results
Open links in new tab
  1. python - Best way to replace multiple characters in a string?

    Mar 19, 2019 · With an input string of abc&def#ghi and replacing & -> \& and # -> \#, the fastest way was to chain together the replacements like this: text.replace('&', '\&').replace('#', '\#'). …

  2. Python String replace() Method - GeeksforGeeks

    Oct 28, 2024 · The replace() method replaces all occurrences of a specified substring in a string and returns a new string without modifying the original string. Let’s look at a simple example of …

  3. Python string.replace() – How to Replace a Character in a String

    Sep 1, 2022 · In this article, I'll show you how this method can be used to replace a character in a string. The replace string method returns a new string with some characters from the original …

  4. Python String replace() Method - W3Schools

    The replace() method replaces a specified phrase with another specified phrase. Note: All occurrences of the specified phrase will be replaced, if nothing else is specified. Required. The …

  5. Replace Character in String Python - PyTutorial

    Feb 9, 2025 · The replace() method is the most common way to replace characters. It takes two arguments. The first is the character to replace. The second is the new character. Here is an …

  6. 4 Efficient Ways to Replace Characters in Python Strings

    Whatever the case may be, there are several ways to replace characters in a string in Python. In this article, we’ll explore four methods for replacing characters in a string. The replace() …

  7. Replacing Characters in a String in Python: A Comprehensive Guide

    Apr 23, 2025 · Regular expressions allow us to define complex patterns to match and replace characters in a string. The re.sub() function is used to perform substitution in a string based on …

  8. python - Changing a character in a string - Stack Overflow

    Aug 4, 2009 · To replace a character in a string. You can use either of the method: Method 1. In general, string = f'{string[:index]}{replacing_character}{string[index+1:]}' Here. text = …

  9. 5 Best Ways to Replace a List of Characters in a String with Python

    Feb 20, 2024 · For example, you want to replace all occurrences of ‘a’, ‘b’, and ‘c’ in the string “abracadabra” with an asterisk ‘*’, to get the result “*br***d*br*”. How can you efficiently …

  10. Python – Replace multiple characters at once - GeeksforGeeks

    Jan 8, 2025 · Removing multiple characters from a string in Python can be achieved using various methods, such as str.replace(), regular expressions, or list comprehensions. Each method …

  11. Some results have been removed
Refresh