Python Forum
Best way to strip() after split()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to strip() after split()
#8
The str object has strip method. Any string is an str object so: "any string".strip()

In [1]: s = "a string"

In [2]: type(s)
Out[2]: str

In [3]: dir(s)
Out[3]: 
# I've removed the __dunder__  functions to shorten the output
['capitalize',
 'casefold',
 'center',
 'count',
 'encode',
 'endswith',
 'expandtabs',
 'find',
 'format',
 'format_map',
 'index',
 'isalnum',
 'isalpha',
 'isdecimal',
 'isdigit',
 'isidentifier',
 'islower',
 'isnumeric',
 'isprintable',
 'isspace',
 'istitle',
 'isupper',
 'join',
 'ljust',
 'lower',
 'lstrip',
 'maketrans',
 'partition',
 'replace',
 'rfind',
 'rindex',
 'rjust',
 'rpartition',
 'rsplit',
 'rstrip',
 'split',
 'splitlines',
 'startswith',
 'strip',                # here it is. 
 'swapcase',
 'title',
 'translate',
 'upper',
 'zfill']

In [4]: type("another string")
Out[4]: str

In [5]: "_strip it_".strip('_') # without an argument stip() will strip the whitespaces -  ' \t\n\r\x0b\x0c'
Out[5]: 'strip it'
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
Best way to strip() after split() - by k357k9 - Nov-03-2017, 11:27 AM
RE: Best way to strip() after split() - by buran - Nov-03-2017, 11:41 AM
RE: Best way to strip() after split() - by Larz60+ - Nov-03-2017, 11:41 AM
RE: Best way to strip() after split() - by buran - Nov-03-2017, 11:45 AM
RE: Best way to strip() after split() - by k357k9 - Nov-03-2017, 12:01 PM
RE: Best way to strip() after split() - by k357k9 - Nov-03-2017, 01:41 PM
RE: Best way to strip() after split() - by DeaD_EyE - Nov-03-2017, 01:54 PM
RE: Best way to strip() after split() - by wavic - Nov-03-2017, 02:09 PM
RE: Best way to strip() after split() - by buran - Nov-03-2017, 02:20 PM
RE: Best way to strip() after split() - by k357k9 - Nov-03-2017, 02:49 PM
RE: Best way to strip() after split() - by buran - Nov-03-2017, 02:56 PM
RE: Best way to strip() after split() - by k357k9 - Nov-03-2017, 03:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 3,203 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
Smile please help me remove error for string.strip() jamie_01 3 1,303 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  Can't strip extra characters from Data Canflyguy 7 2,013 Jan-10-2022, 02:16 PM
Last Post: Canflyguy
  strip() pprod 8 3,634 Feb-16-2021, 01:11 PM
Last Post: buran
  Need help with code for my WS2812B (Neopixel) Led Strip Phibbl 1 2,848 Apr-08-2020, 07:18 PM
Last Post: deanhystad
  split strip issues 'NonType' casacafe 8 4,056 Oct-08-2019, 06:29 PM
Last Post: ichabod801
  removing spaces/tabs after used .strip() zarize 0 1,647 Sep-11-2019, 12:46 PM
Last Post: zarize
  strip off just newlines Skaperen 11 5,545 Jun-19-2019, 06:28 PM
Last Post: Skaperen
  strip space from end of a row of text ineuw 4 3,003 Apr-15-2019, 03:14 AM
Last Post: ineuw
  How to remove whitespace from a string when .replace and .strip do not work winnetrie 7 4,629 Jan-05-2019, 08:44 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020