亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

Python 基礎(chǔ)教程

Python 流程控制

Python 函數(shù)

Python 數(shù)據(jù)類型

Python 文件操作

Python 對(duì)象和類

Python 日期和時(shí)間

Python 高級(jí)知識(shí)

Python 參考手冊(cè)

Python ascii() 使用方法及示例

Python 內(nèi)置函數(shù)

ascii()方法返回一個(gè)字符串,其中包含對(duì)象的可打印表示形式。它使用\x,\u或\U轉(zhuǎn)義符轉(zhuǎn)義字符串中的非ASCII字符。

ascii()的語(yǔ)法為:

ascii(object)

ascii()參數(shù)

ascii()方法采用一個(gè)對(duì)象(例如:字符串,列表等)。

ascii()返回值

它返回一個(gè)包含對(duì)象可打印表示形式的字符串。

例如,?更改為\xf6n,√更改為\u221a

字符串中的非ASCII字符使用\x,\u或\U進(jìn)行轉(zhuǎn)義。

示例1:ascii()方法如何工作?

normalText = 'Python is interesting'
print(ascii(normalText))

otherText = 'Pyth?n is interesting'
print(ascii(otherText))

print('Pyth\xf6n is interesting')

運(yùn)行該程序時(shí),輸出為:

'Python is interesting'
'Pyth\xf6n is interesting'
Pyth?n is interesting

更多實(shí)例

randomList = ['Python', 'Pyth?n', 5]
print(ascii(randomList))

運(yùn)行該程序時(shí),輸出為:

['Python', 'Pyth\xf6n', 5]

Python 內(nèi)置函數(shù)