Private attributes
class Thing:
def __init__(self):
self._name = 'This should be private'
t = Thing()
print(t._name) # This should be private
print(dir(t)) # [..., '_name']
t._name = 'Fake'
print(t._name) # Fake
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
class Thing:
def __init__(self):
self._name = 'This should be private'
t = Thing()
print(t._name) # This should be private
print(dir(t)) # [..., '_name']
t._name = 'Fake'
print(t._name) # Fake