About 212,000 results
Open links in new tab
  1. python - Changing a character in a string - Stack Overflow

    Aug 4, 2009 · If you're changing only one character, then the answer from Jochen Ritzel that uses string slicing is the fastest (and most readable imo). However, if you're going to change …

  2. How do I replace a character in a string with another character in …

    Nov 18, 2012 · Strings in Python are immutable, so you cannot change them in place. Check out the documentation of str.replace : Return a copy of the string with all occurrences of substring …

  3. python - Replacing instances of a character in a string - Stack …

    Oct 4, 2012 · to use the .replace() method effectively on string without creating a separate list for example take a look at the list username containing string with some white space, we want to …

  4. python - Best way to replace multiple characters in a string?

    Mar 19, 2019 · Replacing two characters. I timed all the methods in the current answers along with one extra. With an input string of abc&def#ghi and replacing & -> \& and ...

  5. How to use string.replace () in python 3.x - Stack Overflow

    Feb 26, 2012 · Official doc for str.replace of Python 3. official doc: Python 3's str.replace. str.replace(old, new[, count]) Return a copy of the string with all occurrences of substring old …

  6. python - Replacing a character from a certain index - Stack Overflow

    def replace_str_index(text,index=0,replacement=''): return f'{text[:index]}{replacement}{text[index+1:]}' And then for instance call it with: new_string = …

  7. python - How to replace some characters from the end of a string ...

    I want to replace characters at the end of a python string. I have this string: s = "123123" I want to replace the last 2 with x. Suppose there is a method called …

  8. string - Python Replace \\ with \ - Stack Overflow

    Mar 3, 2015 · In Python string literals, backslash is an escape character. This is also true when the interactive prompt shows you the value of a string. It will give you the literal code …

  9. Replacing a substring of a string with Python - Stack Overflow

    @kwikness - I'm pretty sure Raymond was alluding to Guido van Rossum (python's creator and BDFL (benevolent dictator for life)), Tim Peters (TimSort fame, wrote Zen of Python), and …

  10. python - How do you replace all the occurrences of a certain …

    The problem is that you are not doing anything with the result of replace. In Python strings are immutable so anything that manipulates a string returns a new string instead of modifying the …

Refresh