Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python | slice string by character and not index

Tags:

python-2.7

I want to create variable from a long string to a small string.

e.g abcde!mdamdskm to abcde.

I know only what is the special character and not the index.

like image 454
ariel Avatar asked Feb 02 '16 20:02

ariel


1 Answers

For getting only first word use index after splitting.

a="abcde!mdamdskm"
print a.split("!")[0]
like image 55
Rohit-Pandey Avatar answered Sep 20 '22 14:09

Rohit-Pandey