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

 

相关文章:

  • 2022-12-23
  • 2022-01-03
  • 2021-09-25
  • 2022-02-28
  • 2022-12-23
  • 2021-10-04
猜你喜欢
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-22
  • 2022-01-30
  • 2021-05-28
相关资源
相似解决方案