「Python」ジェネレータ (generator)を使うサンプル

構文
yield 文字列
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
#!/usr/bin/python3
def funccft():
yield "Test001"
yield "Test002"
yield "User003"
res = funccft()
print(next(res))
print(next(res))
print(next(res))
# coding: utf-8 #!/usr/bin/python3 def funccft(): yield "Test001" yield "Test002" yield "User003" res = funccft() print(next(res)) print(next(res)) print(next(res))
# coding: utf-8

#!/usr/bin/python3

def funccft():
            yield "Test001"
            yield "Test002"
            yield "User003"

res = funccft()

print(next(res))
print(next(res)) 
print(next(res))

実行結果
Test001
Test002
User003

Python

Posted by arkgame