TECHIES WORLD

For Techs.... Techniques.... Technologies....

AWSCpanelLinuxPython

How to cut last one element of a string in Python

We can use the Python split utility to cut last one element of a string.

Example script is given below.

s="name:test"
print (s.split(":")[-1:])

Note that, here ":" is used as the separator. We need to change this according to the required separator.

That's all…

Leave a Reply