dir()
A built-in function that lists the names, such as methods and attributes, available on an object or module.
In more detail
dir(str) or dir("") shows every string method. Names starting and ending with two underscores are dunder methods used by Python itself; the rest are the ones you normally call.
Example
[m for m in dir(str) if not m.startswith("_")]Related terms
- help() — A built-in function that shows the documentation, including the docstring, for a function, method, class or module.
- dunder method — A method whose name starts and ends with two underscores, such as __init__ or __len__, which Python calls for you to implement built-in behaviour.
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
Taught in
- Objects, Methods And String Case — Hands-on Python: Complete Video Course & Book
- 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
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep