|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>>> x = "上海自来水来自海上"
>>> x.count("海")
2
>>> x.count("海", 0, 5)
1
>>> x.find("海")
1
>>> x.rfind("海")
7
>>> x.find("龟")
-1
>>> x.index("龟")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found
>>> # 替换
>>> code = """
... print("I love FishC.")
... print("I love my wife.")"""
>>> new_code = code.expandtabs(4)
>>> print(code)
print("I love FishC.")
print("I love my wife.")
>>> print(new_code)
print("I love FishC.")
print("I love my wife.")
>>> "在吗!我在你家楼下,快点下来!!".replace("在吗", "想你")
'想你!我在你家楼下,快点下来!!'
>>> table = str.maketrans("ABCDEFG", "1234567")
>>> "I love FishC.com".translate(table)
'I love 6ish3.com'
>>> "I love FishC.com".translate(str.maketrans("vcCDEFG", "1234567", "love"))
'I 6ish3.2m'
>>> "I love FishC.com".translate(str.maketrans("vcCDEFG", "1234567"))
'I lo1e 6ish3.2om' |
|