“Python”的版本间的差异

来自wrc's Wiki
跳到导航 跳到搜索
第1行: 第1行:
 
== 例子 ==
 
== 例子 ==
 +
 +
=== 实现 [[Rust]] 中的 <code>Iterator::skip</code> ===
 +
 +
忽略一个迭代器的前 n 个元素。
 +
 +
<ref>[https://docs.python.org/3/library/itertools.html#itertools.islice itertools.islice 的文档]</ref>
 +
 +
<syntaxhighlight lang=python>
 +
itertools.islice(iterable, stop)
 +
itertools.islice(iterable, start, stop[, step])
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang=python>
 +
from itertools import islice
 +
 +
islice(iterator, n, None)
 +
</syntaxhighlight>
  
 
=== 类的静态方法 ===
 
=== 类的静态方法 ===
第16行: 第33行:
 
* [https://www.python.org/ 主页]
 
* [https://www.python.org/ 主页]
 
* [https://docs.python.org/ 文档]
 
* [https://docs.python.org/ 文档]
 +
 +
== 参考资料 ==
 +
 +
<references />
  
 
[[Category:Python]]
 
[[Category:Python]]

2021年5月24日 (一) 05:45的版本

例子

实现 Rust 中的 Iterator::skip

忽略一个迭代器的前 n 个元素。

[1]

itertools.islice(iterable, stop)
itertools.islice(iterable, start, stop[, step])
from itertools import islice

islice(iterator, n, None)

类的静态方法

class Example:
    @classmethod
    def load(cls, filepath):
        obj = cls.__new__(cls)
        obj.foo = somefunc(filepath)
        return obj

外部链接

参考资料