代码改变世界

Python 类和实例

2018-04-15 16:42  xx--  阅读(214)  评论(0编辑  收藏  举报
class A(object):
    def __init__(self, host, user, pwd, port):
        self.host = host
        self.user = user
        self.pwd = pwd
        self.port = port
ob_vs = Vsphere("172",
                "local",
                "Server",
                 443)

 

class A(object)定义一个A类继承于object
 # def _init_ 类似于构造函数,第一个参数必须是self
self.host = host为类的属性赋值
ob_vs = Vsphere.__init__("172","local","Server",443)  创建实例时不需要传self参数