python 2day Adv.

  Job 1:

  Job 2:

  Assignment 3:

  


 

  A list = A (2,1, 3)
  a.sort (default ascending) reverse: reverse Flip i.e.

 

  In Python, access the properties and methods of only two, that is, public and private, if you want the property is private property in the name to be used as two underscores beginning.
  Note :
    private variables, before the variable name plus "__"
    private variables can not be inherited, can not call outside, but there may be an internal call.
    If you have to use private variables, you can use dir (class ()) to view its real name.
    If you wanted to have a variable / function is particularly important that you can use the "_"

 

  @property decorator

  recommendation before us is to attribute names that begin with a single underscore to imply that property is protected in this way is not recommended for direct access to the outside world, so if you want to access the property through property getter (accessor) and the setter (modifier) a corresponding operation method.

    Decorator when the need to pay attention to:
    1. decorator names, function names needs to be consistent.
    2. Property need to declare, write setter, the order can not be reversed
    3. If you want just a little variable is accessed can not be modified, You can use accessor the @Property
    4. If you want to modify the accessor variables can build a modifier, or remove accessor.
          # accessor - getter method for
          the @Property
          DEF Age (Self):
            return self._age

          # Modifier - setter Method
            @ age.setter
            DEF Age (Self, Age):
                self._age = Age

                                

                              Exercise

 

 

  Classwork:

        

    import random
    class email(object):
        def __init__(self):
            pass
        def zhuce(self):
            print("请输入邮件地址:")
            res = input('输入')
            print("邮件地址",res,"@163.com")
        def password(self):
            print("请输入密码:")
            self.mima = input('输入')
            print("请再次输入密码:")
            self.querenmima = input('输入')
            if self.mima == self.querenmima:
                print("密码设置成功")
            else:
                print("密码输入错误,请重新设置密码")
                self.password()
        def yanzhengma(self):
            for i in range(1,5):
                if i == 4:
                    exit(0)
                yanzhengma_1=random.randrange(1000,9999)
                print("请输入验证码:",yanzhengma_1)
                yanzhengma_2=int(input("输入"))
                if yanzhengma_1==yanzhengma_2:
                    print("验证通过")
                    self.duanxin()
                    break
                else:
                    pass
    syx=email()
    syx.zhuce()
    syx.password()
    syx.yanzhengma()

                    

              

                    

 

Guess you like

Origin www.cnblogs.com/liwenhui/p/11317433.html