About 51 results
Open links in new tab
  1. How to delete a character from a string using Python

    How to remove one character from a string: Here is an example where there is a stack of cards represented as characters in a string. One of them is drawn (import random module for the …

  2. Remove specific characters from a string in Python

    Oct 15, 2010 · I'm trying to remove specific characters from a string using Python. This is the code I'm using right now. Unfortunately, it appears to do nothing to the string. for char in line: if char in &q...

  3. python - How do I remove a substring from the end of a string …

    927 strip doesn't mean "remove this substring". x.strip(y) treats y as a set of characters and strips any characters in that set from both ends of x. On Python 3.9 and newer you can use the removeprefix …

  4. python - Remove all whitespace in a string - Stack Overflow

    Oct 1, 2016 · All string characters are unicode literal in Python 3; as a consequence, since str.split() splits on all white space characters, that means it splits on unicode white space characters.

  5. python - Remove final character from string - Stack Overflow

    Apr 25, 2022 · I do believe this to be a duplicate of How do I get a substring of a string in Python?. The accepted answer shows how to use [:-2] for removing the last two characters of a string. I believe it …

  6. python - Best way to strip punctuation from a string - Stack Overflow

    Dec 1, 2016 · For the convenience of usage, I sum up the note of striping punctuation from a string in both Python 2 and Python 3. Please refer to other answers for the detailed description.

  7. Is there a simple way to remove multiple spaces in a string?

    Oct 10, 2009 · 65 Using regexes with "\s" and doing simple string.split ()'s will also remove other whitespace - like newlines, carriage returns, tabs. Unless this is desired, to only do multiple spaces, I …

  8. python - How to remove leading and trailing spaces from a string ...

    May 4, 2012 · How to remove leading and trailing spaces from a string? Asked 13 years, 9 months ago Modified 1 year, 2 months ago Viewed 231k times

  9. python - Remove a prefix from a string - Stack Overflow

    Jun 3, 2013 · Obviously (stupid me), because I have used lstrip wrongly: lstrip will remove all characters which appear in the passed chars string, not considering that string as a real string, but as "a set of …

  10. python - Remove last 3 characters of a string - Stack Overflow

    The title asks for removing the last 3 characters of a string, but the first example removes 4 characters and there seem to be more requirements than just removing a given number of characters (like also …