「Python」while文を使うサンプルコード

構文
def 関数名(引数)
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
#!/usr/bin/python3
def funccft(x):
while x < 10:
yield x
x += 2
res = funccft(5)
print(next(res))
print(next(res))
print(next(res))
# coding: utf-8 #!/usr/bin/python3 def funccft(x): while x < 10: yield x x += 2 res = funccft(5) print(next(res)) print(next(res)) print(next(res))
# coding: utf-8

#!/usr/bin/python3

def funccft(x):
      while x < 10:
            yield x
            x += 2
res = funccft(5)

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

実行結果
n>python test.py
5
7
9

Python

Posted by arkgame