The built-in str.partition()
method will do this for you. Unlike str.split()
it won’t bother to cut the rest of the str
into different str
s.
text = raw_input("Type something:")
left_text = text.partition("!")[0]
Explanation
str.partition()
returns a 3-tuple containing the beginning, separator, and end of the string. The [0]
gets the first item which is all you want in this case. Eg.:
"wolfdo65gtornado!salmontiger223".partition("!")
returns
('wolfdo65gtornado', '!', 'salmontiger223')