How do I strip the comma from the end of a string in Python?

str = "hello,"
print str.rstrip(",")

str = "hello,\n"
print str.rstrip(",")
print str.rstrip(",\n")
the output is:
hello
hello,

hello

No comments:

Post a Comment