python基础知识处理

94 阅读1分钟

字符串的处理:

删除前后缀(前缀是从第一个字符串往后开始,后缀同理)

book_name="Python is good"
print(book_name.removeprefix("Pyt"))
print(book_name.removesuffix("od"))
-------------------------------------

hon is good
Python is go

removeprefix("thon")这句代码对字符串就不会产生影响,因为“thon”不是前缀中的部分,(要从P开始)