[英]How to remove certain characters from a string? [Python]
假設我有一個名為cool的字符串,cool設置為“cool°”
cool = "cool°"
如何從字符串中刪除度數符號?
由於字符串是不可變的,因此使用replace函數重新分配cool
cool = "cool°"
cool = cool.replace("°","")
cool
'cool'
如果它們位於字符串的末尾,請使用str.rstrip
:
cool = "cool°"
cool = cool.rstrip("°")
print(cool)
cool
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.