gpt4 book ai didi

python - 当我组合一类数据并分配给一个列表时,Python 中的 [...] 是什么意思?

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

示例

PatientDir = []

class Patient_Data(object):
def __init__(self,first_name,last_name,SSN,more,PatientDir):
self.fn = first_name
self.ln = last_name
self.ssn = SSN
self.more = more
self.pd = PatientDir
print("Patient Created with credentials: ",self.fn,",",self.ln)
def update(self):
PatientDir.append(self.pd)

def getit(self):
print("First Name: ",self.fn)
print("Last NameL ",self.ln)
print("SSN: ",self.ssn)
print("more fields:,",self.more)

patient00000005 = Patient_Data("Julie","Roberton",123121234,
"More fields will be here",PatientDir)
patient00000048 = Patient_Data("Andrew","Johnson",987989876,
"More fields will be here",PatientDir)

现在我很好奇是否可以将这两个病人保存在一个列表中,然后我想看一本字典,看看它是如何工作的。我想看看当我将它们分配给列表时是否可以通过列表或字典访问数据

print(PatientDir)
[[...], [...]]

,当我尝试打印第一个位置时,

PatientDir[1]  
[[...], [...]]

当我尝试在谷歌中搜索时,我没有得到任何结果。所以我找不到下一步如果有步骤的话,你可以这样做吗?我喜欢尝试自己解决问题,但找不到结果......那么这是什么意思?如果可以的话,我将如何提取信息?最后,我当然不会制作一个没有对医疗数据或其他敏感数据进行加密的程序,只是尝试一下。

最佳答案

问题中的...是一个无限递归列表。它不是 Ellipsis 对象的实例,可以测试 l = []; l.append(l); l == [[...]] 将给出 False
第二个是双列表中的 Ellipsis 对象。
(感谢评论中的@Patrick Haugh)

Python Ellipsis :

Ellipsis
The same as .... Special value used mostly in conjunction with extended slicing syntax for user-defined container data types.

This stack overflow question解释了它的作用。

Its interpretation is purely up to whatever implements the getitem function and sees Ellipsis objects there, but its main (and intended) use is in the numeric python extension, which adds a multidimensional array type. Since there are more than one dimensions, slicing becomes more complex than just a start and stop index; it is useful to be able to slice in multiple dimensions as well. E.g., given a 4x4 array, the top left area would be defined by the slice [:2,:2]

关于python - 当我组合一类数据并分配给一个列表时,Python 中的 [...] 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46966969/

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