Python交互提示符中支持TAB自动补全
Python读取命令行选项

迭代器示例

erhuabushuo posted @ 2011年11月14日 14:36 in Python , 1034 阅读

#/usr/bin/env python3.2

class MyIterator():
    
    def __init__(self, step):
        self.step = step
        
    def __next__(self):
        """Returns the next element."""
        if self.step == 0:
            raise StopIteration
        self.step -= 1
        return self.step
    
    def __iter__(self):
        """Returns the iterator itself."""
        return self
    
for el in MyIterator(5):
    print(el, end=" ")  

console:

4 3 2 1 0


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter