跟老齐学Python之编写类之二方法

372次阅读  |  发布于5年以前

数据流转过程

除了在类中可以写这种函数之外,在类中还可以写别的函数,延续上一讲的例子:

复制代码 代码如下:

!/usr/bin/env python

coding:utf-8

class Person:
def init(self, name, lang="golang", website="www.google.com"):
self.name = name
self.lang = lang
self.website = website
self.email = "qiwsir@gmail.com"

def author(self):  
    return self.name

laoqi = Person("LaoQi")
info = Person("qiwsir",lang="python",website="qiwsir.github.io")

print "Author name from laoqi:",laoqi.author()
print "Author name from info:",info.author()

运行结果

Author name from laoqi: LaoQi
Author name from info: qiwsir

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8