liveBook · Manning

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.

How 2 Manning books explain it

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 →

Related concepts

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.