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
Post a Comment