新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python repr()
內(nèi)置函數(shù)repr()用于返回給定對象的可打印表示。返回的輸出將是一個字符串。

創(chuàng)新互聯(lián)建站是專業(yè)的桐鄉(xiāng)網(wǎng)站建設(shè)公司,桐鄉(xiāng)接單;提供成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行桐鄉(xiāng)網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!
**repr(obj)** #where obj can be a string
repr()參數(shù):
接受單個參數(shù)。在許多對象類型和大多數(shù)內(nèi)建模型中。eval()函數(shù)計算作為其參數(shù)給出的表達(dá)式。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 目標(biāo)文件 | 必須返回其可打印表示形式的對象 | 需要 |
返回值
實(shí)際上,repr()函數(shù)調(diào)用給定對象的__repr__()函數(shù)。我們可以__repr__()以便__repr__()以不同的方式工作。
| 投入 | 返回值 | | 目標(biāo)文件 | 字符串表示 |
Python 中repr()方法的示例
示例repr()在 Python 中是如何工作的?
var = 'foo'
print(repr(var))
輸出:
'foo'示例 2:為自定義對象實(shí)現(xiàn) repr ()
class Person:
name = 'Adam'
def __repr__(self):
return repr('Hello ' + self.name )
print(repr(Person()))
輸出:
'Hello Adam'
示例 3:使用類對象
class Color:
color='orange'
def __repr__(self):
return repr(self.color)
o=Color()
repr(o)
輸出:
“‘orange'” 當(dāng)前名稱:創(chuàng)新互聯(lián)Python教程:Python repr()
文章源于:http://www.5511xx.com/article/cciioio.html


咨詢
建站咨詢
