Python str() 函数

实例

把数字 3.5 转换为字符串:

  1. x = str(3.14)

定义和用法

str() 函数将指定的值转换为字符串。

语法

  1. str(object, encoding=encoding, errors=errors)

参数值

参数 描述
object 任何对象。规定要转换为字符串的对象。
encoding 对象的编码。默认是 UTF-8。
errors 规定解码失败时该怎么办。

更多实例

实例

把字符串转换为整数:

  1. x = int("15")