Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
strip()
#1
Hi,
Var1 is a list and I'd like to strip characters from each item in the list and save the result as a new list called Var2. I can't find a way to do it. The code below seemed to be the logical solution but it doesn't work. What am I missing here? Thanks.

for item in Var1:
    Var2 = item.strip('1234 :')
    print(Var2)
Output:
['1234 :A'] ['1234 :B'] ['1234 :C']
Reply


Messages In This Thread
strip() - by pprod - Feb-16-2021, 10:43 AM
RE: strip() - by buran - Feb-16-2021, 10:50 AM
RE: strip() - by pprod - Feb-16-2021, 11:13 AM
RE: strip() - by buran - Feb-16-2021, 11:58 AM
RE: strip() - by pprod - Feb-16-2021, 12:18 PM
RE: strip() - by buran - Feb-16-2021, 12:29 PM
RE: strip() - by pprod - Feb-16-2021, 12:51 PM
RE: strip() - by ndc85430 - Feb-16-2021, 12:51 PM
RE: strip() - by buran - Feb-16-2021, 01:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 3,049 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
Smile please help me remove error for string.strip() jamie_01 3 1,245 Oct-14-2022, 07:48 AM
Last Post: Pedroski55
  Can't strip extra characters from Data Canflyguy 7 1,902 Jan-10-2022, 02:16 PM
Last Post: Canflyguy
  Need help with code for my WS2812B (Neopixel) Led Strip Phibbl 1 2,796 Apr-08-2020, 07:18 PM
Last Post: deanhystad
  split strip issues 'NonType' casacafe 8 3,963 Oct-08-2019, 06:29 PM
Last Post: ichabod801
  removing spaces/tabs after used .strip() zarize 0 1,617 Sep-11-2019, 12:46 PM
Last Post: zarize
  strip off just newlines Skaperen 11 5,414 Jun-19-2019, 06:28 PM
Last Post: Skaperen
  strip space from end of a row of text ineuw 4 2,936 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,509 Jan-05-2019, 08:44 AM
Last Post: DeaD_EyE
  Strip does not work when applied on a string read from a text file. susmis666 1 2,432 Dec-27-2018, 07:07 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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