简体   繁体   English

需要一个整数,chr定义

[英]an integer is required, chr defined

The line of error given is: 给出的错误行是:

letter = chr(input('Enter a letter')).lower()

and the output I recieve is: 我收到的输出是:

TypeError: an integer is required

Is there something that I didn't put? 有没有我没放的东西? I think since I have chr() it should require any single character. 我想因为我有chr(),所以它应该需要任何单个字符。

chr() requires an integer, but input() returns a string. chr()需要一个整数,但是input()返回一个字符串。 Just remove the chr() call: 只需删除chr()调用即可:

letter = input('Enter a letter').lower()

If you wanted to limit the input to just one character, use slicing: 如果要将输入限制为一个字符,请使用切片:

letter = input('Enter a letter')[:1].lower()

Python doesn't have a 'single character' type. Python没有“单个字符”类型。

chr() is only used to turn an integer code point into a (single character) string: chr()仅用于将整数代码点转换为(单个字符)字符串:

>>> chr(65)
'A'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM