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

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -