Mega Code Archive

 
Categories / Python Tutorial / String
 

Strip trailing spaces

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