码迷,mamicode.com
首页 > 编程语言 > 详细

Python中For循环

时间:2018-09-16 21:07:54      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:RoCE   输出   ==   trie   lse   big   proc   ini   put   

1.

for i in range(10):
    print(i)

输出结果

F:\py\pyProject\venv\Scripts\python.exe F:/py/pyProject/venv/while.py
0
1
2
3
4
5
6
7
8
9

Process finished with exit code 0

2.

age_of_oldboy = 56

for i in range(3):
    guess_age =int(input ("guess age:"))
    if guess_age == age_of_oldboy:
        print ("you got it")
        break
    elif guess_age > age_of_oldboy:
        print("think bigger!!!")
    else:
        print("think smaller!!")

else:
     print("you have tried many times...")

输出结果

F:\py\pyProject\venv\Scripts\python.exe F:/py/pyProject/venv/while.py
guess age:23
think smaller!!
guess age:45
think smaller!!
guess age:78
think bigger!!!
you have tried many times...

Process finished with exit code 0

3 for循环隔1个打印出1个,

for i in range(0,10,2):
    print(i)

输出结果为

F:\py\pyProject\venv\Scripts\python.exe F:/py/pyProject/venv/while.py
0
2
4
6
8

Process finished with exit code 0

Python中For循环

标签:RoCE   输出   ==   trie   lse   big   proc   ini   put   

原文地址:https://www.cnblogs.com/wz123/p/9652257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!