Private Attribute (_name)
say it: “UN-der-skor NAYM” /ˈʌndərskɔr ˈneɪm/ or “PRY-vit AT-rih-byoot” /ˈpraɪvɪt ˈætrɪbjut/
An attribute starting with _ that others should leave alone.
What is a private attribute in Python?
A private attribute starts with an underscore, like _balance. Python still lets you touch it; the underscore tells other developers "this is internal, use the methods instead".
class Order:
def __init__(self):
self._items = [] # internal: use add_item()
def add_item(self, item):
self._items.append(item)
Level: Journeyman · More Python terms at this level
Updated