gpt4 book ai didi

Python type() 显示不同的结果

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:41 24 4
gpt4 key购买 nike

我在学习 Python 的同时使用 Sublime Text 2,实际上我只是一个初学者。现在,当我在编辑器中编写 type(1/2) 并构建它 (cmd+B) 时,我得到的输出为 int。相反,如果我在 Sublime 的终端 (ctrl + ` ) 中编写相同的指令,我得到的结果是 float。有人可以向我解释为什么会这样吗?

type(1/2) #in Sublime's editor results: <type 'int'>
type(1/2) #in Sublime's python console results <type 'float'>

我相信它应该是“int”,但为什么还是说“float”。

最佳答案

某处代码从__future__.division导入

>>> type(1/2)
<type 'int'>
>>> from __future__ import division
>>> type(1/2)
<type 'float'>

python2.7

>>> type(1/2)
<type 'int'>

Python 3 将 this 作为一个类进行类型报告,因此它不是使用 python3 的解释器。

python3

>>> type(1/2)
<class 'float'>

关于Python type() 显示不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31040723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com