Reversing a list using slice notation

后端 未结 8 1922
忘掉有多难
忘掉有多难 2020-11-28 22:49

in the following example:

foo = [\'red\', \'white\', \'blue\', 1, 2, 3]

where: foo[0:6:1] will print all elements in foo. Howe

8条回答
  •  猫巷女王i
    2020-11-28 23:09

    If you are having trouble remembering slice notation, you could try doing the Hokey Cokey:

    [In: Out: Shake it all about]

    [First element to include: First element to leave out: The step to use]

    YMMV

提交回复
热议问题