zoukankan      html  css  js  c++  java
  • python练习题之访问限制

    '''
    访问限制:限制别人调用某一些属性或者函数
    好处:提高代码的安全性
    做法:在名字前面加2个下划线__
    如果要赋值或者访问就必须提供setXXX或者getXxx函数
    '''
    class Person:
        def __init__(self):
            self.name=None
            self.__age=None
        def setAge(self,age):
            if age<0:
                print("年龄不合法")
            else:
                self.__age = age
    
        def getAge(self):
            # return self.__age
            print(self.__age)
    
    p=Person()
    p.setAge(10)
    # # print(p.getAge())
    # a=p.getAge()
    # print(a)
    a=p.getAge()
    print(a)
    
    
    # def fun1():
    #     print("fun1")
    #
    #
    # if print(input("请输入:"))<0:
    #     print(111)
    #
    # print(print())
    
    a=input("qingshru")
  • 相关阅读:
    Spring 中各种通知
    Spring 中的注解
    Spring_DI利用set方法赋值Demo
    Beta冲刺总结
    用户使用调查报告
    Beta(7/7)
    Beta(6/7)
    Beta(5/7)
    Beta(4/7)
    Beta(3/7)
  • 原文地址:https://www.cnblogs.com/liangliangzz/p/10159171.html
Copyright © 2011-2022 走看看