Python Forum

Full Version: string slicing help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
why not just split at ' | '?

>>> guitars = 'gibson | fender | ibanez'
>>> guitars = guitars.split(' | ')
>>> guitars[1]
'fender'
Just awesome! Thanks