Python中的内列表问题,真的很困惑
PHP中文网
PHP中文网 2017-04-18 10:25:41
0
1
501
movies=["The Holy Grail",1975,"Terry Jones & Terry Gilliam",91,["Graham Chapman",["Michael Palin","John Cleese","Terry Gilliam","Eric Idle","Terry Jones",]]]
print(movies[4][1][3])

最后得到的是Eric Idle,我不太懂的是,书上说["Graham Chapman",是第二个内列表”movies[4]" 这个4是怎么得出来的? 而第三个内列表叫“movies[4][1],这个4和1又是怎么来的? print[4][1][3] 为什么就能输出Eric Idle ?
零基础初学,真的不太懂,求大神赐教!!
PHP中文网
PHP中文网

认证0级讲师

reply all(1)
刘奇

Python’s array subscripts start from 0.

The fifth element in

movies[4]也就是数组movies:

["Graham Chapman",["Michael Palin","John Cleese","Terry Gilliam","Eric Idle","Terry Jones",]]

The fifth element is also a list

[1] is to take the second element of the fifth element above:

["Michael Palin","John Cleese","Terry Gilliam","Eric Idle","Terry Jones",]

This is still a list, [3]就是取上面这个数组里的第4个元素: Eric Idle, is the result.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template