[Django]-Python left() equivalent?

9👍

You’re looking for slicing:

>>> s = "Hello World!"
>>> print s[2:] # From the second (third) letter, print the whole string
llo World!
>>> print s[2:5] # Print from the second (third) letter to the fifth string
llo
>>> print s[-2:] # Print from right to left
d!
>>> print s[::2] # Print every second letter
HloWrd

So for your example:

>>> s = 'col555'
>>> print s[3:]
555
👤TerryA

2👍

If you know it will always be col followed by some numbers:

>>> int('col1234'[3:])
1234

Leave a comment