When we need to slice a string at a particular location, we need to know the index from where we want to.
For example, in the string:
>>> s = 'Your ID number is: 41233'
I want to slice the string starting from :
and get the number.
Sure I can count at what index :
is and then slice, but is that really a good approach?
Of course I can do a s.index(':')
. But that would be an extra step, so I came up with something like:
>>> print s[(s.index(':')+2):]
41233
But somehow I don't like the looks of it.
So my question is, given a long string which you want to slice, how do you find the index from where to begin the slicing in the easiest and most readable way? If there is a trick to do it orally, I would love to know that.