在 Python 中将整数转换为字符串 [英] Converting integer to string in Python

查看:51
本文介绍了在 Python 中将整数转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Python 中将整数转换为字符串.我徒劳地排版它:

I want to convert an integer to a string in Python. I am typecasting it in vain:

d = 15
d.str()

当我尝试将其转换为字符串时,它显示了一个错误,例如 int 没有任何名为 str 的属性.

When I try to convert it to string, it's showing an error like int doesn't have any attribute called str.

推荐答案

>>> str(10)
'10'
>>> int('10')
10

文档链接:

转换为字符串是使用内置的 str() 函数完成的,该函数基本上调用了 __str__() 其参数的方法.

Conversion to a string is done with the builtin str() function, which basically calls the __str__() method of its parameter.

这篇关于在 Python 中将整数转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆