python3中常用方法
1.isalpha()
str.isalpha():检测字符串是否只由字母组成
1 a = input() 2 for i in a: 3 if not i.isalpha(): 4 print(i)
实现如下:
2.replace()
str.replace('旧字符串','新字符串'):把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次
1 str = "this is string example....wow!!! this is really string" 2 print(str.replace("is", "was")) 3 print(str.replace("is", "was", 3))
实现如下: