Python核心编程笔记(类)

Python并不强求你以面向对象的方式编程(与Java不同)

# coding=utf8

class FooClass(object):

    version = 0.1

    def __init__(self, nm='John Doe'):
        self.name = nm
        print('Created a class instance for', nm)

    def showname(self):
        print('Your name is ', self.name)
        print('My name is ', self.__class__.__name__)

    def shower(self):
        print(self.version)

    def addMe2Me(self, x):
        return (x + x)

foo1 = FooClass()
foo1.showname()
print(foo1.shower())
print(foo1.addMe2Me(5))
print(foo1.addMe2Me('xyz'))

foo2 = FooClass('Jane Smith')
foo2.showname()
上一篇:MQTT研究之EMQ:【SSL双向验证】


下一篇:[Clojure] 包管理器leiningen配置国内镜像仓库