当我尝试使用Chr Python 3时出现问题

时间:2019-12-15 17:14:25

标签: python-3.x chr

我正在使用vs代码,当我尝试运行此代码时: print(str(chr(257))) 我收到此错误:ValueError: chr() arg not in range(256)

1 个答案:

答案 0 :(得分:2)

您似乎正在使用Python 2解释器来运行Python 3代码。如docs for that function in Python 2.7中所述:

  

自变量必须在[0..255]范围内(包括该范围);如果我超出该范围,则会引发ValueError

将您在VS Code中使用的解释器切换为Python 3解释器。