假设我有一个名为 cool 的字符串,它被设置为 "cool°"。
cool = "cool°"
如何从字符串中删除度符号?
由于字符串是不可变的,使用替换函数来重新分配cool
cool
cool = "cool°" cool = cool.replace("°","") cool 'cool'
str.rstrip
cool = "cool°" cool = cool.rstrip("°") print(cool) cool