码迷,mamicode.com
首页 > 编程语言 > 详细

python 几个常用的内置函数

时间:2018-03-20 18:16:28      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:python 几个常用的内置函数

__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 几个常用的内置函数

标签:python 几个常用的内置函数

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!