Python面向对象:在类中定义私有变量和私有方法,python面向对象,# Demonstrat
文章由Byrx.net分享于2019-03-23 07:03:24
Python面向对象:在类中定义私有变量和私有方法,python面向对象,# Demonstrat
# Demonstrates private variables and methodsclass Critter(object): '''A virtual pet''' def __init__(self, name, mood): print 'A new critter has been born!' self.name = name # public attribute self.__mood = mood # private attribute def talk(self): print '\nI'm', self.name print 'Right now I feel', self.__mood, '\n' def __private_method(self): print 'This is a private method.' def public_method(self): print 'This is a public method.' self.__private_method()# maincrit = Critter(name = 'Poochie', mood = 'happy')crit.talk()crit.public_method()
相关内容
- 实现python的: __init__ , __sub__方法,__init___sub_,class Numbe
- python多态,重写父类方法,python多态重写,def rotate_t
- Python获得进程内存使用量的脚本,python获得进程脚本
- python 以可读并且可写方式打开文件,python打开文件,w
- python操作符重写,实现+操作符,python操作符,import str
- Instance Objects,instanceobjects,class Comple
- python中的虚函数,python函数,class Super:
- python代码注释,python注释,# a commenti
- python构造函数,,# def __i
- 输出对象属性,输出对象,class SayMyN
评论关闭