How to trim characters in Python?

Amy W picture Amy W · Aug 14, 2011 · Viewed 9.7k times · Source

Very new to Python and have very simple question. I would like to trim the last 3 characters from string. What is the efficient way of doing this?

Example I am going becomes I am go

Answer

Cydonia7 picture Cydonia7 · Aug 14, 2011

You can use new_str = old_str[:-3], that means all from the beginning to three characters before the end.