我想请教你是如何复制出ipython 里运行指令输出的内容?
[quote=引用 6 楼 maniachhz 的回复:] 我想请教你是如何复制出ipython 里运行指令输出的内容?
这个解释最接近:http://stackoverflow.com/a/9923354/49117,但没考虑start太大的情况: In [48]: a Out[48]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] In [49]: a[11:0:-2] Out[49]: [10, 8, 6, 4, 2] In [50]: a[10:0:-2] # ??? 我以为会返回[9, 7, 5, 3, 1] Out[50]: [10, 8, 6, 4, 2] 好象start太大时,会从最后一个元素开始。
In [48]: a Out[48]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] In [49]: a[11:0:-2] Out[49]: [10, 8, 6, 4, 2] In [50]: a[10:0:-2] # ??? 我以为会返回[9, 7, 5, 3, 1] Out[50]: [10, 8, 6, 4, 2]
slice(start, stop[, step]) Return a slice object representing the set of indices specified by range(start, stop, step). The start and step arguments default to None. Slice objects have read-only data attributes start, stop and step which merely return the argument values (or their default). They have no other explicit functionality; however they are used by Numerical Python and other third party extensions. Slice objects are also generated when extended indexing syntax is used. For example: a[start:stop:step] or a[start:stop, i]. See itertools.islice() for an alternate version that returns an iterator.
37,721
社区成员
34,239
社区内容
加载中
试试用AI创作助手写篇文章吧