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
- string method — A method that belongs to strings, such as upper, lower, count, find, replace, split, strip, startswith or join.
- Boolean — A value that can only be true or false.
Taught in
- Objects, Methods And String Case — Hands-on Python: Complete Video Course & Book
- Split And Join — Hands-on Python: Complete Video Course & Book
- More String Methods — Hands-on Python: Complete Video Course & Book
- Chapter Three In One Sitting — Hands-on Python: Complete Video Course & Book
- Strings: Escapes, Slices And Methods — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Import Variants, dir() And sys.path — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Modules Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Strings Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Class Variables, Instance Variables And __dict__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Special Methods: __str__, __eq__ And Friends — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep