Python中如何进行数据类型转换操作?

2026-05-21 15:380阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计60个文字,预计阅读时间需要1分钟。

Python中如何进行数据类型转换操作?

将字符串'a'赋值为'hello'

bytes<-->str

a="hello" #str字符型

#str转换为bytes类型
b=a.encode("utf-8") 或 b=bytes(a,encoding="utf-8")

#bytes类型转换为str类型
c=b.decode("utf-8") 或 c=str(b,encoding="utf-8")


Python中如何进行数据类型转换操作?


本文共计60个文字,预计阅读时间需要1分钟。

Python中如何进行数据类型转换操作?

将字符串'a'赋值为'hello'

bytes<-->str

a="hello" #str字符型

#str转换为bytes类型
b=a.encode("utf-8") 或 b=bytes(a,encoding="utf-8")

#bytes类型转换为str类型
c=b.decode("utf-8") 或 c=str(b,encoding="utf-8")


Python中如何进行数据类型转换操作?