Typical classes and methods of invocation:
#!/usr/bin/env Python#Coding=utf-8__metaclass__= Type#New ClassclassPerson:#Create Class def __init__(self, name):#initialization functionSelf.name =Name
defGetName (self):#methods (functions) in a class returnSelf.name
defcolor (self, color):Print "%s is%s"%(self.name, color)
Girl= Person ('Wangguniang')#instantiation ofName = Girl.getname ()#Call Method (function)Print "The person's name is:", Namegirl.color (" White")#Call Method (function)Print "------"PrintGirl.name#properties of the instance
Operation Result:
The property data for self must not necessarily be passed in by a parameter, or it can be set in the constructor itself
#/bin/env/python#Coding:utf-8__metaclass__=typeclassPerson :def __init__(Self, name,general="male"): Self.name=name Self.email="[email protected]"self.general=GeneralInfo= Person ("Keven")Print "info.name=", Info.namePrint "info.email=", Info.emailPrint "info.general=", info.general
Operation Result:
Python Learning note 12-Class