首页 > 编程语言 > 详细

python 几个常用的内置函数

时间:2018-03-20 17:57:35      阅读:227      评论:0      收藏:0      [点我收藏+]
__init__

__new__

__repr__

__str__


这几个函数的优先级分别是

new,str,repr,init

看下面的例子:

技术分享图片

技术分享图片

技术分享图片

技术分享图片

class A:
	def __str__(self):
		return "this is str"
	def __init__(self,value="hello world !"):
		self.value = value
	def __new__(self):
		return "this is new"
	def __repr__(self):
		return "this is repr"

a=A()

print(a)

由上面的例子可以看出他们的出场顺序

python 几个常用的内置函数

原文:http://blog.51cto.com/853056088/2089084

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!