Python str() 函數
描述
str() 函數將對象轉化為適於人閱讀的形式。
語法
以下是 str() 方法的語法:
class str(object='')
參數
- object -- 對象。
返回值
返回一個對象的string格式。
實例
以下展示了使用 str() 方法的實例:
>>> s = 'RUNOOB' >>> str(s) Traceback (most recent call last): File "<pyshell#86>", line 1, in <module> str(s) TypeError: 'str' object is not callable >>> dict = {'runoob':'runoob.com','google':'google.com'}; >>> str(dict) Traceback (most recent call last): File "<pyshell#88>", line 1, in <module> str(dict) TypeError: 'str' object is not callable >>> import str Traceback (most recent call last): File "<pyshell#89>", line 1, in <module> import str ModuleNotFoundError: No module named 'str' >>>