msg = ‘hello alex‘ # 定义变量 msg1 = msg.replace(‘alex‘,‘SB‘) # 将alex字符串替换成SB print(type(msg1),msg1)
输出结果:
<class ‘str‘> hello SB
练习:将下面的alex字符串替换成SB
原文:http://www.cnblogs.com/yujiemeigui/p/7077303.html