{"id":7405,"date":"2024-04-04T19:01:01","date_gmt":"2024-04-04T11:01:01","guid":{"rendered":""},"modified":"2024-04-04T19:01:01","modified_gmt":"2024-04-04T11:01:01","slug":"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7405.html","title":{"rendered":"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

Python\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09<\/h3>\n

1\u3001abs() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        \u6c42\u6570\u7684\u7edd\u5bf9\u503c\u6216\u8005\u590d\u6570\u7684\u6a21<\/p>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n# abs:<\/span> \u6c42\u7edd\u5bf9\u503c or \u590d\u6570\u7684\u6a21\n\n# \uff5c-<\/span>1<\/span>\uff5c=<\/span>1<\/span>\na=<\/span>abs<\/span>(<\/span>-<\/span>1<\/span>)<\/span>\n# \u590d\u6570 3<\/span>+<\/span>4<\/span>j\u7684\u6a21\nb=<\/span>abs<\/span>(<\/span>3<\/span>+<\/span>4<\/span>j)<\/span>\n\n#\u6253\u5370\u7ed3\u679c\nprint<\/span>(<\/span>'-1\u7684\u7edd\u5bf9\u503c\uff1a'<\/span>,<\/span>a)<\/span>\nprint<\/span>(<\/span>'3+4j \u7684\u6a21\uff1a'<\/span>,<\/span>b)<\/span>\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
2\u3001all() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        \u7528\u4e8e\u5224\u65ad\u7ed9\u5b9a\u7684\u53ef\u8fed\u4ee3\u53c2\u6570 iterable \u4e2d\u7684\u6240\u6709\u5143\u7d20\u662f\u5426\u90fd\u4e3a TRUE<\/font>,\u5982\u679c\u662f\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002\u5143\u7d20\u9664\u4e86\u662f 0\u3001\u7a7a\u3001None\u3001False \u5916\u90fd\u7b97 True\u3002
\u6ce8\u610f\uff1a\u7a7a\u5143\u7ec4\u3001\u7a7a\u5217\u8868\u8fd4\u56de\u503c\u4e3aTrue<\/font><\/p>\n

\u8bed\u6cd5<\/strong><\/p>\n

all<\/span>(<\/span>iterable)<\/span>\n\u53c2\u6570\uff1aiterable --<\/span> \u5143\u7ec4\u6216\u5217\u8868\u3002\n<\/code><\/pre>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n# \u5217\u8868list\uff0c\u5143\u7d20\u90fd\u4e0d\u4e3a\u7a7a\u62160<\/span>  True\nprint<\/span>(<\/span>all<\/span>(<\/span>[<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> 'c'<\/span>,<\/span> 'd'<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u5217\u8868list\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a\u7a7a\u7684\u5143\u7d20 False\nprint<\/span>(<\/span>all<\/span>(<\/span>[<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> ''<\/span>,<\/span> 'd'<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u5217\u8868list\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a0<\/span>\u7684\u5143\u7d20 False\nprint<\/span>(<\/span>all<\/span>(<\/span>[<\/span>0<\/span>,<\/span>1<\/span>,<\/span>2<\/span>,<\/span>3<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u5143\u7ec4tuple\uff0c\u5143\u7d20\u90fd\u4e0d\u4e3a\u7a7a\u62160<\/span> True\nprint<\/span>(<\/span>all<\/span>(<\/span>(<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> 'c'<\/span>,<\/span> 'd'<\/span>)<\/span>)<\/span>)<\/span>\n\n# \u5143\u7ec4tuple\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a\u7a7a\u7684\u5143\u7d20 False\nprint<\/span>(<\/span>all<\/span>(<\/span>(<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> ''<\/span>,<\/span> 'd'<\/span>)<\/span>)<\/span>)<\/span>\n\n# \u5143\u7ec4tuple\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a0<\/span>\u7684\u5143\u7d20 False \nprint<\/span>(<\/span>all<\/span>(<\/span>(<\/span>0<\/span>,<\/span> 1<\/span>,<\/span> 2<\/span>,<\/span> 3<\/span>)<\/span>)<\/span>)<\/span>\n\n# \u7a7a\u5217\u8868 True\nprint<\/span>(<\/span>all<\/span>(<\/span>[<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u7a7a\u5143\u7ec4 True\nprint<\/span>(<\/span>all<\/span>(<\/span>(<\/span>)<\/span>)<\/span>)<\/span>\n\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
3\u3001any() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        \u7528\u4e8e\u5224\u65ad\u7ed9\u5b9a\u7684\u53ef\u8fed\u4ee3\u53c2\u6570 iterable \u662f\u5426\u5168\u90e8\u4e3a False<\/font>\uff0c\u5219\u8fd4\u56de False\uff0c\u5982\u679c\u6709\u4e00\u4e2a\u4e3a True\uff0c\u5219\u8fd4\u56de True\u3002\u5143\u7d20\u9664\u4e86\u662f 0\u3001\u7a7a\u3001FALSE \u5916\u90fd\u7b97 TRUE\u3002
\u8bed\u6cd5<\/strong><\/p>\n

any<\/span>(<\/span>iterable)<\/span>\n\u53c2\u6570\uff1aiterable --<\/span> \u5143\u7ec4\u6216\u5217\u8868\u3002\n<\/code><\/pre>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n# \u5217\u8868list\uff0c\u5143\u7d20\u90fd\u4e0d\u4e3a\u7a7a\u62160<\/span>  True\nprint<\/span>(<\/span>any<\/span>(<\/span>[<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> 'c'<\/span>,<\/span> 'd'<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u5217\u8868list\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a\u7a7a\u7684\u5143\u7d20 True\nprint<\/span>(<\/span>any<\/span>(<\/span>[<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> ''<\/span>,<\/span> 'd'<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u5217\u8868list\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a0<\/span>\u7684\u5143\u7d20 True\nprint<\/span>(<\/span>any<\/span>(<\/span>[<\/span>0<\/span>,<\/span>1<\/span>,<\/span>2<\/span>,<\/span>3<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u5217\u8868list\uff0c\u4e3a0<\/span> \u7a7a false<\/span> False\nprint<\/span>(<\/span>any<\/span>(<\/span>[<\/span>0<\/span>,<\/span>''<\/span>,<\/span>False]<\/span>)<\/span>)<\/span>\n\n# \u5143\u7ec4tuple\uff0c\u5143\u7d20\u90fd\u4e0d\u4e3a\u7a7a\u62160<\/span> True\nprint<\/span>(<\/span>any<\/span>(<\/span>(<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> 'c'<\/span>,<\/span> 'd'<\/span>)<\/span>)<\/span>)<\/span>\n\n# \u5143\u7ec4tuple\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a\u7a7a\u7684\u5143\u7d20 True\nprint<\/span>(<\/span>any<\/span>(<\/span>(<\/span>'a'<\/span>,<\/span> 'b'<\/span>,<\/span> ''<\/span>,<\/span> 'd'<\/span>)<\/span>)<\/span>)<\/span>\n\n# \u5143\u7ec4tuple\uff0c\u5b58\u5728\u4e00\u4e2a\u4e3a0<\/span>\u7684\u5143\u7d20 True\nprint<\/span>(<\/span>any<\/span>(<\/span>(<\/span>0<\/span>,<\/span> 1<\/span>,<\/span> 2<\/span>,<\/span> 3<\/span>)<\/span>)<\/span>)<\/span>\n\n# \u5143\u7ec4tuple\uff0c\u4e3a 0<\/span> \u7a7a False False\nprint<\/span>(<\/span>any<\/span>(<\/span>(<\/span>0<\/span>,<\/span>''<\/span>,<\/span>False)<\/span>)<\/span>)<\/span>\n\n# \u7a7a\u5217\u8868 False\nprint<\/span>(<\/span>any<\/span>(<\/span>[<\/span>]<\/span>)<\/span>)<\/span>\n\n# \u7a7a\u5143\u7ec4 False\nprint<\/span>(<\/span>any<\/span>(<\/span>(<\/span>)<\/span>)<\/span>)<\/span>\n\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
4\u3001ascii() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        1.\u8c03\u7528\u5bf9\u8c61\u7684 __ repr __ \u65b9\u6cd5\uff0c\u83b7\u5f97\u8be5\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002
        2.\u8fd4\u56de\u4efb\u4f55\u5bf9\u8c61\uff08\u5b57\u7b26\u4e32\uff0c\u5143\u7ec4\uff0c\u5217\u8868\u7b49\uff09\u7684\u53ef\u8bfb\u7248\u672c,\u5c06\u6240\u6709\u975e ascii \u5b57\u7b26\u66ff\u6362\u4e3a\u8f6c\u4e49\u5b57\u7b26\uff1a<\/p>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n#\u5b9a\u4e49\u7c7b Student\nclass<\/span> Student<\/span>(<\/span>)<\/span>:<\/span>\n    def __init__<\/span>(<\/span>self,<\/span> id,<\/span> name)<\/span>:<\/span>\n        self.<\/span>id =<\/span> id\n        self.<\/span>name =<\/span> name\n\n    def __repr__<\/span>(<\/span>self)<\/span>:<\/span>\n        return<\/span> 'id = '<\/span>+<\/span>self.<\/span>id +<\/span> ', name = '<\/span>+<\/span>self.<\/span>name\n\n\n#\u58f0\u660e\u5bf9\u8c61 xiaoming\nxiaoming =<\/span> Student<\/span>(<\/span>id=<\/span>'1'<\/span>,<\/span> name=<\/span>'xiaoming'<\/span>)<\/span>\nprint<\/span>(<\/span>xiaoming)<\/span>\nprint<\/span>(<\/span>ascii<\/span>(<\/span>xiaoming)<\/span>)<\/span>\n\n#\u8f6c\u4e49\nprint<\/span>(<\/span>ascii<\/span>(<\/span>\"haihong\"<\/span>)<\/span>)<\/span>\nprint<\/span>(<\/span>ascii<\/span>(<\/span>\"\u6d77\u8f70\"<\/span>)<\/span>)<\/span>\n\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
5\u3001bin() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        \u5341\u8fdb\u5236\u8f6c\u4e3a\u4e8c\u8fdb\u5236\u3002 \u8fd4\u56de\u4e00\u4e2a\u6574\u6570 int \u6216\u8005\u957f\u6574\u6570 long int \u7684\u4e8c\u8fdb\u5236\u8868\u793a\u3002\u8fd4\u56de\u503c\u662f\u5b57\u7b26\u4e32<\/strong>\u3002<\/p>\n

\u8bed\u6cd5<\/strong><\/p>\n

bin<\/span>(<\/span>x)<\/span>\n\u53c2\u6570\nx --<\/span> int \u6216\u8005 long int \u6570\u5b57\n<\/code><\/pre>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n#bin \u5341\u8fdb\u5236\u8f6c\u4e8c\u8fdb\u5236\n# 1000<\/span>=<\/span>1100100<\/span>\nprint<\/span>(<\/span>bin<\/span>(<\/span>100<\/span>)<\/span>)<\/span>\n\n#2<\/span>=<\/span>10<\/span>\nprint<\/span>(<\/span>bin<\/span>(<\/span>2<\/span>)<\/span>)<\/span>\n\n#8<\/span>=<\/span>1000<\/span>\nprint<\/span>(<\/span>bin<\/span>(<\/span>8<\/span>)<\/span>)<\/span>\n\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\u6ce8\uff1a0b \u8868\u793a \u4e8c\u8fdb\u5236
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
6\u3001oct() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        \u5c06\u4e00\u4e2a\u6574\u6570\u8f6c\u6362\u6210 8 \u8fdb\u5236\u5b57\u7b26\u4e32<\/strong>\u3002
\u8bed\u6cd5<\/strong><\/p>\n

oct<\/span>(<\/span>x)<\/span>\n\u53c2\u6570\u8bf4\u660e\uff1ax --<\/span> \u6574\u6570\u3002\n<\/code><\/pre>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n#bin \u5341\u8fdb\u5236\u8f6c\u516b\u8fdb\u5236\n# 1000<\/span>=<\/span>144<\/span>\nprint<\/span>(<\/span>oct<\/span>(<\/span>100<\/span>)<\/span>)<\/span>\n\n#2<\/span>=<\/span>2<\/span>\nprint<\/span>(<\/span>oct<\/span>(<\/span>2<\/span>)<\/span>)<\/span>\n\n#8<\/span>=<\/span>10<\/span>\nprint<\/span>(<\/span>oct<\/span>(<\/span>8<\/span>)<\/span>)<\/span>\n\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
7\u3001hex() <\/font>
\u4f5c\u7528<\/strong>
        \u7528\u4e8e\u5c0610\u8fdb\u5236\u6574\u6570\u8f6c\u6362\u621016\u8fdb\u5236\uff0c\u4ee5\u5b57\u7b26\u4e32<\/strong>\u5f62\u5f0f\u8868\u793a\u3002
\u8bed\u6cd5<\/strong><\/p>\n

hex<\/span>(<\/span>x)<\/span>\n\u53c2\u6570\u8bf4\u660e\uff1ax --<\/span> 10<\/span>\u8fdb\u5236\u6574\u6570\n<\/code><\/pre>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n#bin \u5341\u8fdb\u5236\u8f6c\u5341\u516d\u8fdb\u5236\n# 1000<\/span>=<\/span>64<\/span>\nprint<\/span>(<\/span>hex<\/span>(<\/span>100<\/span>)<\/span>)<\/span>\n\n#2<\/span>=<\/span>2<\/span>\nprint<\/span>(<\/span>hex<\/span>(<\/span>2<\/span>)<\/span>)<\/span>\n\n#8<\/span>=<\/span>8<\/span>\nprint<\/span>(<\/span>hex<\/span>(<\/span>8<\/span>)<\/span>)<\/span>\n\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
8\u3001bool() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        \u7528\u4e8e\u5c06\u7ed9\u5b9a\u53c2\u6570\u8f6c\u6362\u4e3a\u5e03\u5c14\u7c7b\u578b\uff0c\u5982\u679c\u6ca1\u6709\u53c2\u6570\uff0c\u8fd4\u56de False\u3002bool \u662f int \u7684\u5b50\u7c7b<\/font>,<\/p>\n

\u8bed\u6cd5<\/strong><\/p>\n

class<\/span> bool<\/span>(<\/span>[<\/span>x]<\/span>)<\/span>\n\u53c2\u6570\uff1ax --<\/span> \u8981\u8fdb\u884c\u8f6c\u6362\u7684\u53c2\u6570\u3002\n<\/code><\/pre>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n#bool<\/span>(<\/span>)<\/span> \n#\u7a7a False\nprint<\/span>(<\/span>bool<\/span>(<\/span>)<\/span>)<\/span>\n#0<\/span> False\nprint<\/span>(<\/span>bool<\/span>(<\/span>0<\/span>)<\/span>)<\/span>\n#1<\/span> True\nprint<\/span>(<\/span>bool<\/span>(<\/span>1<\/span>)<\/span>)<\/span>\n#\u7a7a\u5143\u7ec4 False\nprint<\/span>(<\/span>bool<\/span>(<\/span>(<\/span>)<\/span>)<\/span>)<\/span>\n\n#\u5143\u7ec4 True\nprint<\/span>(<\/span>bool<\/span>(<\/span>(<\/span>1<\/span>,<\/span>2<\/span>,<\/span>3<\/span>)<\/span>)<\/span>)<\/span>\n\n#\u5143\u7ec4 True\nprint<\/span>(<\/span>bool<\/span>(<\/span>(<\/span>0<\/span>,<\/span>1<\/span>,<\/span>2<\/span>)<\/span>)<\/span>)<\/span>\n\n#\u5143\u7ec4 True  \u6613\u9519\nprint<\/span>(<\/span>bool<\/span>(<\/span>(<\/span>0<\/span>,<\/span>)<\/span>)<\/span>)<\/span>\n\n#\u7a7a\u5217\u8868 Fasle\nprint<\/span>(<\/span>bool<\/span>(<\/span>[<\/span>]<\/span>)<\/span>)<\/span>\n\n#\u5217\u8868 True\nprint<\/span>(<\/span>bool<\/span>(<\/span>[<\/span>1<\/span>]<\/span>)<\/span>)<\/span>\n\n#\u5217\u8868 True  \u6613\u9519\nprint<\/span>(<\/span>(<\/span>bool<\/span>(<\/span>[<\/span>0<\/span>]<\/span>)<\/span>)<\/span>)<\/span>\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
9\u3001bytes() <\/font><\/p>\n

\u4f5c\u7528<\/strong>
        \u8fd4\u56de\u4e00\u4e2a\u65b0\u7684 bytes \u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u662f\u4e00\u4e2a 0 <= x < 256 \u533a\u95f4\u5185\u7684\u6574\u6570\u4e0d\u53ef\u53d8\u5e8f\u5217\u3002\u5b83\u662f bytearray \u7684\u4e0d\u53ef\u53d8\u7248\u672c\u3002<\/p>\n

\u8bed\u6cd5<\/strong><\/p>\n

class<\/span> bytes<\/span>(<\/span>[<\/span>source[<\/span>,<\/span> encoding[<\/span>,<\/span> errors]<\/span>]<\/span>]<\/span>)<\/span>\n\n\u53c2\u6570:<\/span>\n  \u5982\u679c source \u4e3a\u6574\u6570\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u957f\u5ea6\u4e3a source \u7684\u521d\u59cb\u5316\u6570\u7ec4\uff1b\n  \u5982\u679c source \u4e3a\u5b57\u7b26\u4e32\uff0c\u5219\u6309\u7167\u6307\u5b9a\u7684 encoding \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u8282\u5e8f\u5217\uff1b\n  \u5982\u679c source \u4e3a\u53ef\u8fed\u4ee3\u7c7b\u578b\uff0c\u5219\u5143\u7d20\u5fc5\u987b\u4e3a[<\/span>0<\/span> ,<\/span>255<\/span>]<\/span> \u4e2d\u7684\u6574\u6570\uff1b\n  \u5982\u679c source \u4e3a\u4e0e buffer \u63a5\u53e3\u4e00\u81f4\u7684\u5bf9\u8c61\uff0c\u5219\u6b64\u5bf9\u8c61\u4e5f\u53ef\u4ee5\u88ab\u7528\u4e8e\u521d\u59cb\u5316 bytearray\u3002\n  \u5982\u679c\u6ca1\u6709\u8f93\u5165\u4efb\u4f55\u53c2\u6570\uff0c\u9ed8\u8ba4\u5c31\u662f\u521d\u59cb\u5316\u6570\u7ec4\u4e3a0<\/span>\u4e2a\u5143\u7d20\u3002\n<\/code><\/pre>\n

\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\na =<\/span> bytes<\/span>(<\/span>[<\/span>1<\/span>,<\/span>2<\/span>,<\/span>3<\/span>,<\/span>4<\/span>]<\/span>)<\/span>\nprint<\/span>(<\/span>a)<\/span>\n\n# hello:<\/span>\u5b57\u7b26\u4e32 ascii:<\/span>\u7f16\u7801\u65b9\u5f0f\nb =<\/span> bytes<\/span>(<\/span>'hello'<\/span>,<\/span>'ascii'<\/span>)<\/span>\nprint<\/span>(<\/span>b)<\/span>\n\n\nc=<\/span>\"haihong\"<\/span>\nprint<\/span>(<\/span>bytes<\/span>(<\/span>c,<\/span>encoding=<\/span>\"utf-8\"<\/span>)<\/span>)<\/span>\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09
10\u3001str() <\/font>
\u4f5c\u7528<\/strong>
        \u5c06\u5bf9\u8c61\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32<\/strong>
\u6d4b\u8bd5demo<\/strong><\/p>\n

#!<\/span>\/<\/span>usr\/<\/span>bin\/<\/span>python3\n\n#\u6570\u5b57\u8f6c\u5b57\u7b26\u4e32\nprint<\/span>(<\/span>str<\/span>(<\/span>222<\/span>)<\/span>)<\/span>\n\n#\u5217\u8868\u8f6c\u5b57\u7b26\u4e32\nprint<\/span>(<\/span>str<\/span>(<\/span>[<\/span>1<\/span>,<\/span>2<\/span>,<\/span>3<\/span>]<\/span>)<\/span>)<\/span>\n\n#\u5143\u7ec4\u8f6c\u5b57\u7b26\u4e32\nprint<\/span>(<\/span>str<\/span>(<\/span>(<\/span>1<\/span>,<\/span>2<\/span>,<\/span>4<\/span>)<\/span>)<\/span>)<\/span>\nprint<\/span>(<\/span>type<\/span>(<\/span>str<\/span>(<\/span>(<\/span>1<\/span>,<\/span>2<\/span>,<\/span>4<\/span>)<\/span>)<\/span>)<\/span>)<\/span>\n\n<\/code><\/pre>\n

\u8fd0\u884c\u7ed3\u679c<\/strong>
\"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09<\/p>\n

\u53c2\u8003\u8d44\u6599<\/h3>\n
\n

https:\/\/github.com\/jackzhenguo\/python-small-examples
https:\/\/www.runoob.com\/python\/python-built-in-functions.html<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"Python\u5b66\u4e60\u7b14\u8bb0\uff084\uff09\uff5ePython\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff09Python\u57fa\u7840\u7ec3\u4e60\u4e4b\u5e38\u7528\u5185\u7f6e\u51fd\u6570\uff081-10\uff091\u3001abs()\u4f5c\u7528\u6c42\u6570\u7684\u7edd\u5bf9\u503c...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7405"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7405"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7405\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}