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

查看:293
本文介绍了在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天全站免登陆