Python शब्दचिह्न encode() मेथड
इस्तरा
शब्दचिह्न को UTF-8 एनकोड करें:
txt = "My name is Ståle" x = txt.encode() print(x)
व्याख्या और उपयोग
encode() मेथड निर्दिष्ट एनकोडिंग के साथ शब्दचिह्न को एनकोड करता है। यदि एनकोडिंग निर्दिष्ट नहीं होता, तो UTF-8 का उपयोग किया जाएगा।
व्याकरण
string.encode(encoding=encoding, errors=errors)
पारामीटर मान
पारामीटर | वर्णन |
---|---|
encoding | वैकल्पिक। शब्दचिह्न रूपकृत। इस्तेमाल की जाने वाली एनकोडिंग को निर्दिष्ट करता है। मूलभूत एनकोडिंग UTF-8 है। |
errors |
वैकल्पिक। शब्दचिह्न रूपकृत। त्रुटि विधि को निर्दिष्ट करता है। वैध मान हैं:
|
और अधिक इस्तरा
इस्तरा
ये इस्तराह एस्की एनकोडिंग और अनकोडिंग नहीं किए जाने वाले अक्षरों का उपयोग करके, विभिन्न त्रुटि के साथ दिखाया जाता है:
txt = "My name is Ståle" print(txt.encode(encoding="ascii",errors="backslashreplace")) print(txt.encode(encoding="ascii",errors="ignore")) print(txt.encode(encoding="ascii",errors="namereplace")) print(txt.encode(encoding="ascii",errors="replace")) print(txt.encode(encoding="ascii",errors="xmlcharrefreplace")) print(txt.encode(encoding="ascii",errors="strict"))