Python取代()函数:替换字符串中某个字符的方法

  介绍

这篇文章主要介绍了Python取代()函数:替换字符串中某个字符的方法,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

<强>

str.replace(旧的,新的[,max])

<强>

<强>

# !/usr/bin/Python   str =,“却;能够is  string 例子....哇! ! !,却;能够is  really  string";   print  str.replace(“女儿家,“was");   print  str.replace(“女儿家,“was",, 3);

<强>

thwas  was  string 例子....哇! ! !,thwas  was  really 字符串   ,   thwas  was  string 例子....哇! ! !,thwas  is  really 字符串

Python取代()函数:替换字符串中某个字符的方法