startswith()

String methods that answer whether a string begins, or ends, with a given piece of text, returning True or False.

In more detail

name.endswith(".py") checks a file name; line.startswith("#") spots a comment. Either can take a tuple of options, as in s.startswith(("a", "an", "the")).

Example

"hello.py".endswith(".py")

Related terms

Taught in

References

Certification courses