We can do this by the rstrip() function Example :s="programming "s=s.rstrip() // "programming"
Example :
s="programming "
s=s.rstrip()
// "programming"