4

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?

2 Answers 2

7

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

cool = "cool°"
cool = cool.replace("°","")
cool
'cool'
Sign up to request clarification or add additional context in comments.

Comments

3

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

cool = "cool°"

cool = cool.rstrip("°")
print(cool)
cool

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.