python oop面向对象笔记

#coding:utf-8

class Person(object):
def __init__(self,name,wage):
self.name = name
self.wage = wage

def func(self):
return '123'

@property #方法变为属性
def attr(self):
return '123'

def computer(self):
return '555'

#类成员 (字段,方法,属性)

obj = Person('jack',20000)
print(obj.func())
print(obj.attr)

#类成员:方法

class Province(object):
def __init__(self,name):
pass

def f1(self): #普通方法
pass

@classmethod #类方法
def f2(cls):
print("i am f2")
print(cls)

@staticmethod #静态方法
def f3():
print("i am f3")

# obj = Province()
# obj.f1()

Province.f2() #调用都用类
Province.f3()
posted @ 2017-02-05 15:04  tonyklose1984  阅读(281)  评论(0编辑  收藏  举报