python 判断字符串是否以j、jc、J、JC开头
可以使用字符串的startswith()方法来判断一个字符串是否以指定的前缀开头。
string = "jcPython"
if string.startswith("j") or string.startswith("J"):
print("字符串以j或J开头")
elif string.startswith("jc") or string.startswith("JC"):
print("字符串以jc或JC开头")
else:
print("字符串不以j、jc、J、JC开头")
输出:
字符串以jc或JC开头
原文地址: https://www.cveoy.top/t/topic/ins3 著作权归作者所有。请勿转载和采集!