Python代码中如何入判断一个字符串的开头、结尾

python判断的开头结尾有快捷方法如下:

1、判断开头:

string.startswith("目标字符")

2、判断结尾:

string.endswith("目标字符")

判断的结果:

True  or  False

3、判断之前请先去除字符串首尾空格,方法:

string.strip()

猜你喜欢

转载自blog.csdn.net/msq16021/article/details/112622845