【发布时间】:2020-07-02 06:27:00
【问题描述】:
ls = [16, 81, 23, 74, 91, 612, 33, 812]
ls[2:6:3] #Starting from index 2 till index 5 and skip the next 2 indices
ls[::-1] # Reverse list is printed
只执行第二行,即ls[::-1]。我做错了什么?
【问题讨论】:
-
Jupyter 只会输出块中最后一个表达式的结果。如您所见,所有语句都已执行。第二条语句被执行,但结果被丢弃,因为它没有分配给任何东西。
-
@JanChristophTerasa 谢谢,但有什么办法可以同时显示两者吗?
-
print它们,或者分成两个块,或者将两个表达式放在一行上(这将返回一个元组)。
标签: python python-3.x jupyter-notebook ipython