我的单子不起作用,一直说认股权证没有定义

2024-09-27 17:49:18 发布

您现在位置:Python中文网/ 问答频道 /正文

names=[ 
    ["Scott Walters","W12345",11],
    ["Rishi Goomar","G67890",8],
    ["Chris Flading","F45678",2],
    ["Chris Dearnley","D23456",10],
    ["Nick Smetana","S90123",5],
    ["Lukasz Morysewicz","M78901",15],
    ["Sravya Boddu","B34567",7],
    ["John Venderley","V56789",4]
    ]

for i in names:
         i= names, license, warrants
         print names[i],license[i],warrants[i]

为什么这样不行? 它说我不知道该怎么做


Tags: nameslicensescottnickchrisrishiwarrantswalters
2条回答

使用开箱包装。你知道吗

for i in names:
    names, license, warrants = i # for first time i = ['Scott Walters', 'W12345', 11]
    print names, license, warrents

这里

i[0] = names, i[1] = license, i[2] = warrents

把你的陈述翻过来。你的作业是向后的:

i= names, license, warrants

应该是

names, license, warrants = i
print names,license,warrants

这将输出:

Scott Walters W12345 11
Rishi Goomar G67890 8
Chris Flading F45678 2
Chris Dearnley D23456 10
Nick Smetana S90123 5
Lukasz Morysewicz M78901 15
Sravya Boddu B34567 7
John Venderley V56789 4

Dive Into Python可以看到一个很好的教程,它包含了一次分配多个值。你知道吗

相关问题 更多 >

    热门问题