【问题标题】:Why are lists giving different value?为什么列表赋予不同的价值?
【发布时间】: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/….
  • laalist[1] 的一个元素。 alist[1][2]la 怎么可能是 2 以外的任何值?
  • @DavidS 是的,但我不知道 alist[1] 对 [4%len(alist[1])] 做了什么

标签: python arrays list


【解决方案1】:

查看列表的索引值。

alist=[[1],[2]]

这里alist[1][2],所以alist[1][0]2

4%10

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2018-07-15
    相关资源
    最近更新 更多