Python 数据类型

标签 python types

这个说法是真的吗?

Python does not enforce a strict type on containers or variables. With this concept, developers can design a container to hold different types of data

我正在写一篇关于 Python 的文章,在 random site 上找到了这条语句,只是想知道是否有人可以为我澄清一下。

最佳答案

是的,这是真的。

除了设计一个容器,常规列表还可以容纳多种类型

>>> myList = [1, 3.14, 'string', {'key1':'value1'}, frozenset([5,2,2,3]), [1,2,3],(5+2j),(4.0,5.0), True, type(5)]
>>> myList
[1, 3.1400000000000001, 'string', {'key1': 'value1'}, frozenset([2, 3, 5]), [1, 2, 3], (5+2j), (4.0, 5.0), True, <type 'int'>]
>>> [type(x) for x in myList]
[<type 'int'>, <type 'float'>, <type 'str'>, <type 'dict'>, <type 'frozenset'>, <type 'list'>, <type 'complex'>, <type 'tuple'>, <type 'bool'>, <type 'type'>]

甚至 type 也是一个类型

关于Python 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4642032/

相关文章:

python - 在数据框中对一列进行求和,同时保留其他列

python : replacing a space after numbers keeping space after letters

C#:Oracle 数据类型与 OracleDbType 等价

haskell - 在haskell中,如何表示新定义的无限数据

Python 多处理 - 调试 OSError : [Errno 12] Cannot allocate memory

python - 如何通过查询向mysql表中添加新列

python - Altair:从 Vega 配色方案中选择一种颜色用于绘图

c++ - 将 (void*) 转换为 std::vector<unsigned char>

sql - 如何添加时间戳和整数类型的两列

C++ 原始数据类型 : how to read unsigned 30 bits