目录

工欲善其事

实践出真知

活跃标签: linux java mysql 待分类 js springboot win10 电路 vue macOS nginx windows esp32 git docker idea maven esp8266 python Arduino

存档:

X

Python 从入坑到入门V01

1、对象

python中判断对象的方式为type() ,但是字符串转换的方式却不太一样
字节转换成字符串,如下:

bytes1 = b'i am bytes'  # 是字节,验证类型
print(type(Bytes_str))

str_1 = Bytes_str.decode('utf-8')  # str_1是字符串类型,转换类型
print(type(str_1))  # 验证类型

字符串转换成字节,如下:

str2 = 'i am str'  # 创建字符串,并查看类型
print(type(str2))

bytes1 = str2.encode()  # 转换类型,并验证
print(type(bytes1))

bs = b'testing bytes'  # 使用小 ‘b’ 也可将字符串转换成bytes(字节)
print(type(bs))  # 验证类型

标题:Python 从入坑到入门V01
作者:llilei
地址:http://solo.llilei.work/articles/2023/01/17/1673966679611.html