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

前端 未结 1 810
感情败类
感情败类 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)
提交回复
热议问题