gpt4 book ai didi

python - 这在 Python 中是什么? (类型相关)

转载 作者:太空宇宙 更新时间:2023-11-04 10:39:15 25 4
gpt4 key购买 nike

我是 Python 的新手,而且我正在上课。

我是这样做的:

>>> x = int()
>>> x
0
>>> type(x)
<type 'int'>
>>> x = str()
>>> type(x)
<type 'str'>
>>> x = tuple
>>> type(x)
<type 'type'>
>>> x = ()
>>> type(x)
<type 'tuple'>
>>> x = blak
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'blak' is not defined

为什么将 tuple 分配给新创建的变量会赋予它 type 类型,而不是赋予它元组类型? (我同意它不给出元组类型,因为 x = () 做到了。)任何其他词,它(显然)会给出错误。

我在这里偶然发现了什么?我在文档中找不到任何内容,因为搜索引擎并不是很有用。

此外,现在我看看是否x = 海峡或者x = int

也导致

type(x) = int

同样

最佳答案

x = tuple 是一种类型。 x = tuple() 将是一个元组...

关于python - 这在 Python 中是什么? (类型相关),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722787/

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