当前位置: 动力学知识库 > 问答 > 编程问答 >

How to remove certain characters from a string? [Python]

问题描述:

Say i have a string called cool and cool is set to "cool°"

cool = "cool°"

how do i remove the degree symbol from the string?

网友答案:

Since strings are immutable, use the replace function to reassign cool

cool = "cool°"
cool = cool.replace("°","")
cool
'cool'
网友答案:

If they are at the end of the string use str.rstrip:

cool = "cool°"

cool = cool.rstrip("°")
print(cool)
cool
分享给朋友:
您可能感兴趣的文章:
随机阅读: