新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)Python教程:python中repr函數(shù)作用是什么?
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。

1、repr() 函數(shù)
得到的字符串通常可以用來(lái)重新獲得該對(duì)象,將對(duì)象轉(zhuǎn)化為供解釋器讀取的形式。
2、語(yǔ)法
repr(a)
3、參數(shù)
a: 對(duì)象。
4、返回值
返回一個(gè)對(duì)象的 string 格式。
5、使用實(shí)例
class test:
def __init__(self,name,age):
self.age = age
self.name = name
def __repr__(self):
return "Class_Test[name="+self.name+",age="+str(self.age)+"]"
t = test("Zhou",30)
print(t)repr()的輸入對(duì)python比較友好,大家可以放心使用哦~
當(dāng)前標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中repr函數(shù)作用是什么?
文章出自:http://m.fisionsoft.com.cn/article/dhiejoh.html


咨詢
建站咨詢
