import string badSentence = "\t\tThis sentence has problems. " #Strip trailing spaces print "Length = " + str(len(badSentence)) print "Without trailing spaces = " + str(len(badSentence.rstrip(' ')))