【发布时间】:2021-02-14 15:35:29
【问题描述】:
**嘿伙计们,我被这个问题困住了**
alist=[[1],[2]]
la=alist[1][4%len(alist[1])] #when i run this i get the output 2
al=4%len(alist[1]) #when i run this i get the output 0
谁能解释一下原因?
【问题讨论】:
-
您期待什么?为什么?
-
@khelwood 我不明白为什么调用 la 给出 2 ,我明白为什么 al 给出 0 。你能解释一下在拉发生了什么吗?
-
@LEONARDO 你熟悉模运算吗? freecodecamp.org/news/….
-
la是alist[1]的一个元素。alist[1]是[2]。la怎么可能是 2 以外的任何值? -
@DavidS 是的,但我不知道 alist[1] 对 [4%len(alist[1])] 做了什么