Sometimes, we want to check whether a string starts with XXXX with Python.
In this article, we’ll look at how to check whether a string starts with XXXX with Python.
How to check whether a string starts with XXXX with Python?
To check whether a string starts with XXXX with Python, we can use the startswith
method.
For instance, we write
a_string = "hello world"
a_string.startswith("hello")
to call a_string.startswith
to check if a_string
starts with 'hello'
.
Conclusion
To check whether a string starts with XXXX with Python, we can use the startswith
method.