简体   繁体   English

python 列表如何管理不同数据类型的值?

[英]How does python lists manage values of different data types?

If I am not wrong, python lists are linked lists, lets say we have a list如果我没记错的话,python 列表是链表,假设我们有一个列表

L =['a',34]

According to my understanding it looks like this根据我的理解,它看起来像这样

 _  __       ___ __
|_a|_*| --> |_34|__| 

And from C we know that pointer next to 'a' will point to a data type similar to its own, ie in this case a 'char', but how does python here manage to do this从 C 中我们知道,'a' 旁边的指针将指向一个类似于它自己的数据类型,即在这种情况下是一个 'char',但是这里的 python 如何做到这一点

I tried to see the source code it hurt my head, can someone please explain its working in simple words我试图查看源代码,它让我头疼,有人可以用简单的话解释一下它的工作原理吗

Edit: I've been banned from posting after posting this question and I don't understand why编辑:发布这个问题后我被禁止发布,我不明白为什么

I'm not sure, but I think every variable in python is actually stored as a structure, containing datatype and then the raw data.我不确定,但我认为 python 中的每个变量实际上都存储为一个结构,包含数据类型,然后是原始数据。 So behind the scenes every variable is actually of the same type (which is this structure).所以在幕后,每个变量实际上都是相同的类型(就是这个结构)。

https://realpython.com/python-variables/ https://realpython.com/python-variables/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用不同的数据类型对 Python 中的列表进行排序 - Sort a list of lists in Python with different data types python如何在数组中具有不同的数据类型? - How does python have different data types in an array? Python如何区分不同的数据类型? - How does Python differentiate between the different data types? 如何比较两个长度相同(但数据类型不同)的列表及其对应的值? - How to compare two lists of same length (but different data types) and their corresponding values? 在python中用不同类型的值绘制数据 - Plot data with different types of values in python 如何使用 Python 找到由不同数据类型组成的两个列表之间的差异 - How to find the difference between two lists consisted of different data types with Python 如何在循环中输入多种数据类型(int,float,string)并将其排序到python中的不同列表中? - How to input mutilple data types (int, float, string) in a loop and sort it into different lists in python? Python - “加入”不同类型列表的列表 - Python - “Joining” list of lists of different types python-在列表中查找不同类型的通用元素 - python - find common elements of different types in lists python-映射两个不同类型的列表 - python - map two lists of different types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM