#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File  : 13.保护变量.py
# Author: HuXianyong
# Mail: mghxy123@163.com
# Date  : 2019/5/17 0017

'''
保护变量
    在变量名前使用一个下划线，称为保护变量
'''

class Person:
    def __init__(self,name,age=18):
        self.name = name
        self._age = age

tom = Person('Tom')
print(tom._age)
print(tom.__dict__)
f1c694234797ab63e757325a3f9fae59820c6657
<mask token>

<mask token>


class Person:

    def __init__(self, name, age=18):
        self.name = name
        self._age = age


<mask token>

<mask token>


class Person:

    def __init__(self, name, age=18):
        self.name = name
        self._age = age


<mask token>
print(tom._age)
print(tom.__dict__)

<mask token>


class Person:

    def __init__(self, name, age=18):
        self.name = name
        self._age = age


tom = Person('Tom')
print(tom._age)
print(tom.__dict__)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File  : 13.保护变量.py
# Author: HuXianyong
# Mail: mghxy123@163.com
# Date  : 2019/5/17 0017

'''
保护变量
    在变量名前使用一个下划线，称为保护变量
'''

class Person:
    def __init__(self,name,age=18):
        self.name = name
        self._age = age

tom = Person('Tom')
print(tom._age)
print(tom.__dict__)