There are 2 ways to do this. Suppose you have a string a = "maddy". Now refer to the code below.
1. The first way is simply by using string slicing. For example,
a[:-3] will simply remove the last 3 characters of the string.
2. The second way to do it is by suing rstrip(). For example, suppose that we have the same string a = "maddy"
The rstrip() removes characters from the right based on the argument (a string specifying the set of characters to be removed).