Leading underscore convention
The leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions.
Web Components in Action
- How it is used
- Signals which Web Component properties and methods consumers should treat as internal rather than part of the public API.
- How deep it goes
- Distinguishes convention-based signaling from actual privacy and demonstrates internal state behind setters.
- Examples
- Uses _addItemToUI, _searchTerm, _apiKey, public setters, and redraw behavior as concrete examples.
- What you can do after
- Apply it by naming internal component state and methods with underscores while exposing deliberate public properties.
Read how Web Components in Action explains leading underscore convention →
Python How-To
- How it is used
- Signals that class methods or attributes are intended for internal use and reduces irrelevant IDE autocomplete suggestions.
- How deep it goes
- Defines the naming convention and its autocomplete effects, while stopping short of enforcing access restrictions.
- Examples
- Uses _format_note, protected class members, and a challenge to rename applicable methods as nonpublic.
- What you can do after
- Apply it via Python naming conventions to communicate which methods and attributes users should avoid calling directly.
Read how Python How-To explains leading underscore convention →
Also covered in
- Practices of the Python Pro
- The Quick Python Book, Fourth Edition
- Vanilla WebIn early access (MEAP)
What to know first
- moduleA module is a cohesive unit of code or computation that groups related functionality within a larger system and defines a scope or boundary for organizing or sharing it.
- attributeAn attribute is a named property or piece of information associated with an entity, object, or structured data item.
- PythonPython is a high-level, general-purpose, dynamically typed programming language with readable syntax and support for multiple programming paradigms.
- classA class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating or representing objects.
Related concepts
- private memberconfigures · A private member is a program element whose direct access is restricted to its defining class, module, file, or other language-defined scope.
- conventionkind of · A convention is an accepted or agreed practice for organizing, naming, or implementing things consistently.
- protected memberconfigures · A protected member is a class attribute or method accessible within its defining class and, subject to language rules, within subclasses or other related contexts.
- tuple unpackinguses · Tuple unpacking is assigning the elements of an iterable to multiple corresponding targets in a single operation.
Questions about leading underscore convention
What is leading underscore convention?
The leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions.
Which Manning books explain leading underscore convention?
Web Components in Action and Python How-To.
What should I know before learning leading underscore convention?
Manning books that teach leading underscore convention usually introduce module, attribute, Python and class first.
What is the difference between leading underscore convention and private field?
The leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions. A JavaScript private field is a class field declared with a leading # that can be accessed only from within the class that declares it.
What is leading underscore convention a kind of?
Leading underscore convention is a kind of convention. A convention is an accepted or agreed practice for organizing, naming, or implementing things consistently.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

