gpt4 book ai didi

python - 无法理解此代码片段的输出

转载 作者:行者123 更新时间:2023-12-01 00:06:19 25 4
gpt4 key购买 nike

i = 1
while (i < 10):
i += 1
print(i),
print(type(i)),
Output 

2
3
4
5
6
7
8
9
10
<class 'int'>

Out[16]: (None,)

当我在最后一行后给出逗号时,我无法理解为什么我们会在输出中得到 Out[16]: (None,) 。

最佳答案

出现这种情况是因为 print() 函数返回 None。因此,运行

print(type(i)),

在你的控制台中相当于运行

None,

将一个元组输出到控制台,即

(None,)

关于python - 无法理解此代码片段的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59953014/

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