python怎么输入整数
发布时间:2025-05-08 10:44:19
使用input()函数输入一个整数:
a=input(请输入一个整数\n”)
相关推荐:Python基础教程
结果是Typeerororororor: 'str' object cannot be interpreted as an integer
查看文件,发现input()函数返回值为str型。
我们只需要这样转换:
a=int(input("请输入一个整数"))(强制类型转换,其他同理)或使用a=eval(input("请输入一个整数"))(自动类型转换)
下一篇 python怎么写csv文件