Python Forum
string slicing help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: string slicing help (/thread-25169.html)



string slicing help - oli_action - Mar-22-2020

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


RE: string slicing help - buran - Mar-22-2020

why not just split at ' | '?

>>> guitars = 'gibson | fender | ibanez'
>>> guitars = guitars.split(' | ')
>>> guitars[1]
'fender'



RE: string slicing help - oli_action - Mar-22-2020

Just awesome! Thanks