Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string slicing help
#1
Hi guys,

I'm new to coding and i've started teaching myself Python and am currently learning "string slicing".

I need help with the following:

guitars = 'gibson | fender | ibanez'
guitars.index("|")
7
stock2020 = guitars[:guitars.index("|")]
stock2020
'gibson '
How would I get the second guitar( | fender | ) on a seperate "excel block"? How do i get to the second pipe or any following same letter(i) without counting? Wall

Thanks
Reply
#2
why not just split at ' | '?

>>> guitars = 'gibson | fender | ibanez'
>>> guitars = guitars.split(' | ')
>>> guitars[1]
'fender'
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Just awesome! Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  String slicing and loop iteration divyansh 9 1,990 Jun-07-2020, 10:29 PM
Last Post: divyansh
  String slicing divyansh 6 1,181 May-31-2020, 06:15 AM
Last Post: pyzyx3qwerty
  Accepting strings as arguments when slicing a string? (Ziyad Yehia on Udemy) Drone4four 4 1,261 Aug-23-2019, 07:59 PM
Last Post: Drone4four
  string slicing default value Uchikago 1 1,130 Jul-01-2019, 11:19 AM
Last Post: perfringo
  string slicing Uchikago 2 1,076 Jun-28-2019, 06:35 AM
Last Post: perfringo
  String slicing in python from reverse ift38375 1 1,077 Apr-29-2019, 06:58 AM
Last Post: perfringo
  String Slicing in List Comphrensions Patroclus72790 1 1,091 Mar-21-2019, 09:33 PM
Last Post: nilamo
  String slicing problem Ollew 4 1,444 Sep-08-2018, 08:07 PM
Last Post: Ollew
  String Slicing jack 9 5,441 May-04-2017, 11:36 AM
Last Post: buran
  Problem with slicing string YatishK 2 2,120 Apr-24-2017, 09:46 AM
Last Post: YatishK

Forum Jump:

User Panel Messages

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