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.
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.
For getting only first word use index after splitting.
a="abcde!mdamdskm"
print a.split("!")[0]
>>> "abcde!mdamdskm".split("!")
['abcde', 'mdamdskm']
This might not work if you have multiple instances of the special character:
>>> "abcde!mdam!dskm".split("!")
['abcde', 'mdam', 'dskm']
But you could fix that like this:
>>> "abcde!mdam!dskm".split("!", 1)
['abcde', 'mdam!dskm']