📜  python 访问修饰符 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:34.043000             🧑  作者: Mango

代码示例1
# In python access modifying can be done by prefixing the underscore character '_' to the variable name.

# Prefixing no underscores makes the variable public.
# Prefixing 1 underscore makes the variable protected.
# Prefixing 2 underscores makes the variable private.

# In the following example, name is public, __make is private, _model is protected.
class Car:
    def __init__(self):
        print("Engine started")
        self.__make = "toyota"
        self._model = 1999
        self.name = "corolla"