python startswith() 函数

 

startswith()

 作用:判断字符串是否以指定字符或子字符串开头

 

>>> s = "my name is ming"
>>>
>>> s.startswith('m')
True
>>> s.startswith('b')
False
>>>

 

常用环境:用于if判断

>>> if s.startswith('hel'):
 print ("you are right")
else:
 print ("you are wrang")
  
# 执行结果
you are right

 

posted @ 2018-01-03 18:01  minger_lcm  阅读(299)  评论(0编辑  收藏  举报