【问题标题】:Why The isinstance method not working inside for loop?为什么 isinstance 方法在 for 循环中不起作用?
【发布时间】:2022-06-17 15:40:13
【问题描述】:

我正在尝试使用 isinstance 来验证对象是否为浮点数,当不在 for 循环内但在 for 循环内其给定的错误输出时,该方法似乎工作正常,这里有什么问题请建议

print(isinstance(-98.3,float))

N = int(input(""))

for i in range(N):
    n = input("")
    print(n, isinstance(n, float))


True
3
1
1 False
-312
-312 False
**10.00
10.00 False # wrong here** 

【问题讨论】:

  • input 总是返回一个字符串...

标签: python python-3.x


猜你喜欢
  • 2013-11-12
  • 2023-02-22
  • 2013-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多