Skip to content

Instantly share code, notes, and snippets.

@rswofxd
Created March 23, 2012 13:26
Show Gist options
  • Save rswofxd/2170608 to your computer and use it in GitHub Desktop.
Save rswofxd/2170608 to your computer and use it in GitHub Desktop.
Class类操作
# -*- coding:utf-8 -*-
class MyClass:
'"A simple example class"'
__name__ #.........default property........
__bases__ # when class is named
__dict__ #.........data property...........
def __init__(self,vars1,vars2): #'self' is the default first arg for function in a class
self.m = vars1
self.n = vars2
..... #called when class is exampled,and return 'None'
def fun(self):
return 'hello world'
x = MyClass(4,6) #example object call and initiate
>>>x.m ,x.n ,x.fun #call property of class
>>>x.__doc__ #"A simple example class"---"docstring", '__'is not '_',私有属性,私有方法,对于Shell具有特别意义
x.fun() #direct call
y = x.fun #indirect call
class DerivedClassName(BaseClassName):
.............
class DerivedClassName(modname.BaseClassName):
.............
class DerivedClassName(Base1,Base2,Base3...):
.............
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment