基本数据类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基本数据类型相关的知识,希望对你有一定的参考价值。
1、bytes
2、string
bytes类型转成string,直接使用decode()进行转化。
1 byte_out = stdout.read() 2 print(type(byte_out)) 3 print(byte_out) 4 print(type(byte_out.decode())) 5 print(byte_out.decode())
结果:
<class ‘bytes‘> b‘ens160 Link encap:Ethernet HWaddr 00:50:56:99:a8:a2 \n inet addr:124.207.138.20 Bcast:124.207.138.31 Mask:255.255.255.240\n inet6 addr: fe80::250:56ff:fe99:a8a2/64 Scope:Link\n UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1\n RX packets:90175 errors:0 dropped:0 overruns:0 frame:0\n TX packets:39222 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1000 \n RX bytes:29697887 (29.6 MB) TX bytes:8603589 (8.6 MB)\n\nlo Link encap:Local Loopback \n inet addr:127.0.0.1 Mask:255.0.0.0\n inet6 addr: ::1/128 Scope:Host\n UP LOOPBACK RUNNING MTU:65536 Metric:1\n RX packets:3423 errors:0 dropped:0 overruns:0 frame:0\n TX packets:3423 errors:0 dropped:0 overruns:0 carrier:0\n collisions:0 txqueuelen:1 \n RX bytes:209665 (209.6 KB) TX bytes:209665 (209.6 KB)\n\n‘ <class ‘str‘> ens160 Link encap:Ethernet HWaddr 00:50:56:99:a8:a2 inet addr:124.207.138.20 Bcast:124.207.138.31 Mask:255.255.255.240 inet6 addr: fe80::250:56ff:fe99:a8a2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:90175 errors:0 dropped:0 overruns:0 frame:0 TX packets:39222 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:29697887 (29.6 MB) TX bytes:8603589 (8.6 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:3423 errors:0 dropped:0 overruns:0 frame:0 TX packets:3423 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:209665 (209.6 KB) TX bytes:209665 (209.6 KB) Process finished with exit code 0
以上是关于基本数据类型的主要内容,如果未能解决你的问题,请参考以下文章