Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.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中输入字母表_Python_Python 3.x - Fatal编程技术网

如何在python中输入字母表

如何在python中输入字母表,python,python-3.x,Python,Python 3.x,所以我想对字母表做同样的处理,就像我对数字做的一样。看一看 num1=int(input("enter Ist digit:")) num2=int(input("enter IInd digit:")) num3=int(input("enter IIIrd digit:")) num4=int(input("enter IVth digit:")) num5=int(input("enter Vth digit:")) 我想输入字母而不是数字 所以我把它改成了 alpha1=chr(inp

所以我想对字母表做同样的处理,就像我对数字做的一样。看一看

num1=int(input("enter Ist digit:"))
num2=int(input("enter IInd digit:"))
num3=int(input("enter IIIrd digit:"))
num4=int(input("enter IVth digit:"))
num5=int(input("enter Vth digit:"))
我想输入字母而不是数字 所以我把它改成了

alpha1=chr(input("enter Ist letter"))
但我一直在犯错误

   alpha1=chr(input("enter Ist alphabet:"))
TypeError: an integer is required (got type str)
阅读:

chr(一)

返回一个字符串,其ASCII码为整数i

输入([提示])

如果存在prompt参数,则将其写入标准输出,而不带尾随换行符。然后,函数从输入中读取一行,将其转换为字符串(去掉尾随的换行符),并返回该字符串

您不需要转换角色。您从输入中得到的已经是一个字符串
AlpHA1=输入(“输入IST字母”)< /P> < P> Python将标准输入视为字符串,在第一种情况下,将字符串转换为整数。但在第二种情况下,它将不起作用,因为它以字符串形式获取输入,并且chr(param)总是期望一个整数值,其中param应该是一个整数值(0-9)。因此,只需使用以下方法:-

alpha1=(input("enter Ist alphabet:"))[0]
Python没有“字符”数据类型。它只是
str()
,与输入函数是冗余的