rstrip(char_set) removes all characters in char_set from the right side of a string: #!/usr/bin/python3
txt = 'msd45q63v742'
#
# Remove all digits from the right side:
#
txt_ = txt.rstrip('0123456789')
print(txt_) # msd45q63v
rstrip is to remove line breaks from a string's end: rstrip('\n\r'). This is especially useful when the strings are read by iterating over each line in a file. This somewhat imitates the chomp() function in Perl. str = str[:-n] (See extracting substrings from strings).