Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
定义python程序时如何将int格式转换为字符串格式_Python_Python 2.7_Type Conversion - Fatal编程技术网

定义python程序时如何将int格式转换为字符串格式

定义python程序时如何将int格式转换为字符串格式,python,python-2.7,type-conversion,Python,Python 2.7,Type Conversion,我想把我的输入从int转换成string,但我做不到!这是我的密码!请帮忙 def hi(x): print x 如果我给x写了一个字母,就会出现一条错误信息!我不想在双引号内给出我的输入。如果不这样做,有什么办法吗?非常简单 def hi(intx): target = ''.format(intx) print target 因此,您的参数是一个整数,但是当您执行str(x)时,您会将数据类型更改为string。请您稍微清楚一点好吗?你能给出一些例子错误消

我想把我的输入从int转换成string,但我做不到!这是我的密码!请帮忙

 def hi(x):

       print x
如果我给x写了一个字母,就会出现一条错误信息!我不想在双引号内给出我的输入。如果不这样做,有什么办法吗?

非常简单

def hi(intx):
   target = ''.format(intx)
   print target 

因此,您的参数是一个整数,但是当您执行str(x)时,您会将数据类型更改为string。

请您稍微清楚一点好吗?你能给出一些例子错误消息来自哪里,错误消息是什么?例如,如果我键入hi(klmnop),它会给出类似“klmnop未定义”的错误消息!Python的规则#1,内置方法用于类型转换
str(x)
@Tharushigethma不幸的是,这是重复的。是的,但这并不意味着你的问题很清楚。这确实是一个重复的问题,主持人是对的。如果问题解决了,别忘了接受答案。
def hi(x):
    print(type(x))
    x= str(x)
    print(type(x))