slice - Best way to get first n characters of the string in Python -


i need first n characters of string of x characters, n = x - len(endstring) , endstring can have number of characters 0 x.

is there cleaner , better performance-wise way in python beside:

string[:len(string) - len(endstring)] 

?

main point len(string) looks little redundant, account endstring of 0 characters seemed "smoothest" solution?

you can string[:-len(endstring) or none] instead.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -