(一)删除首尾特定字符:
1、S.strip([chars]):删除字符串S首尾特定字符(序列)chars,默认为空格;
2、S.lstrip([chars]):删除字符串S开头特定字符(序列)chars,默认为空格;
3、S.rstrip([chars]):删除字符串S尾部特定字符(序列)chars,默认为空格。
(二)判断首尾字符:
1、S.startswith(sub,start=num1,end=num2):检查字符串S[start,end]是否是以指定子字符串sub开头
2、S.endswith(suffix,start=num1,end=num2):检查字符串S[start,end]是否是以指定子字符串suffix结尾
print("Dogs and cats!".startswith("Do")) # True
print("Dogs and cats!".startswith("Don't")) # False
print("-------")
print("Dogs and cats!".endswith("!")) # True
print("Dogs and cats!".endswith("rats!")) # False