av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)Python教程:Python encode()

python 中的encode()函數(shù)有助于將給定的字符串轉(zhuǎn)換為編碼格式。如果未指定編碼,默認(rèn)情況下將使用 UTF-8。

創(chuàng)新互聯(lián)從2013年成立,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元唐山做網(wǎng)站,已為上家服務(wù),為唐山各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話(huà):028-86922220

 **string.encode(encoding='UTF-8',errors='strict')** #where encodings being utf-8, ascii, etc 

編碼()參數(shù):

encode()函數(shù)接受兩個(gè)可選參數(shù)。這里的參數(shù)錯(cuò)誤有六種類(lèi)型。

  • 失敗時(shí)的嚴(yán)格默認(rèn)響應(yīng)。
  • 忽略-忽略不可編碼的 unicode
  • replace -將不可編碼的 unicode 替換為問(wèn)號(hào)(?)
  • XML arreffreplace-它不是不可編碼的 unicode,而是插入 XML 字符引用
  • backslashreplace 插入\ uNNNN 轉(zhuǎn)義序列,而不是不可編碼的 unicode
  • 名稱(chēng)替換-它插入了一個(gè)\N{而不是不可編碼的 unicode...}轉(zhuǎn)義序列
參數(shù)描述必需/可選
編碼字符串必須編碼到的編碼類(lèi)型可選擇的
錯(cuò)誤編碼失敗時(shí)的響應(yīng)可選擇的

編碼()返回值

默認(rèn)情況下,函數(shù)使用 utf-8 編碼,如果出現(xiàn)任何故障,它會(huì)引發(fā)一個(gè) UnicodeDecodeError 異常。

| 投入 | 返回值 | | 線(xiàn) | 編碼字符串 |

Python 中encode()方法的示例

示例 1:如何將字符串編碼為默認(rèn)的 Utf-8 編碼?

 # unicode string
string = 'pyth?n!'

# print string
print('The original string is:', string)

# default encoding to utf-8
string_utf8 = string.encode()

# print result
print('The encoded string is:', string_utf8) 

輸出:

 The original string is: pyth?n!
The encoded string is: b'pyth\xc3\xb6n!'

示例 2:編碼如何處理錯(cuò)誤參數(shù)?

 # unicode string
string = 'pyth?n!'

# print string
print('The original string is:', string)

# ignore error
print('The encoded string (with ignore) is:', string.encode("ascii", "ignore"))

# replace error
print('The encoded string (with replace) is:', string.encode("ascii", "replace")) 

輸出:

 The original string is: pyth?n!
The encoded string (with ignore) is: b'pythn!'
The encoded string (with replace) is: b'pyth?n!'

網(wǎng)頁(yè)題目:創(chuàng)新互聯(lián)Python教程:Python encode()
文章轉(zhuǎn)載:http://uogjgqi.cn/article/djeepoh.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流