suchen

Heim  >  Fragen und Antworten  >  Hauptteil

python 一次性替换多个字符

a = 'New York,NY2016'
如何一次性把空格替换成+号,然后逗号替换成%
用replace貌似只能替换一个,能多个吗?
谢谢

高洛峰高洛峰2887 Tage vor671

Antworte allen(3)Ich werde antworten

  • PHPz

    PHPz2017-04-17 17:42:12

    a.replace(' ','+').replace(',','%')

    Antwort
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:42:12

    可以写一个正则表达式

    Antwort
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:42:12

    用translation试试

    Antwort
    0
  • StornierenAntwort