Basic private attribute
Input
get_private_attribute(Vault('gold'), 'secret')
Output
gold
Vault stores its secret as __secret. Name-mangling hides it, but our helper finds _Vault__secret and returns 'gold'.
Full lesson preview
Learn how Python name-mangles double-underscore attributes and implement a helper that retrieves values whether they are public, protected, or name-mangled private.
Problem statement
Task
Examples
Input
get_private_attribute(Vault('gold'), 'secret')
Output
gold
Vault stores its secret as __secret. Name-mangling hides it, but our helper finds _Vault__secret and returns 'gold'.
Input format
Output format
Constraints
Samples
Input
get_private_attribute(Note('remember'), 'note')
Output
remember
Note stores _note (single underscore). The helper checks the single-underscore variant and returns the value.