Python初识米面向对象

一、Python初识面向对象

1.1 封装

class Person:
    country='中国'                 #静态字段,可以直接调用
    def __init__(self,name,pwd):  #Python类自带的内置,会自动加载
        self.name=name
        self.pwd=pwd
    def login(self):
        if self.name=="xj" and self.pwd==123456:
            print("login ok")

obj=Person("xj",123456)            #对象=类名()
obj.login()                        #对象可以调用内部的方法(也叫动态属性)

  

猜你喜欢

转载自www.cnblogs.com/so-cool/p/9063265.html