In Python 3, how do I determine if a prefix is in a string?

前端 未结 1 803
感情败类
感情败类 2021-01-25 22:23

I need to recursively write a function that determines if a prefix, for example \'f\', is the prefix of a string. If it is the prefix, it needs to return True, and if it is not

相关标签:
1条回答
  • 2021-01-25 22:50

    Use startswith method :

    if(string.startswith(prefix)) :
        do something
    
    0 讨论(0)
提交回复
热议问题