韩漫免费漫画在线观看方法,《好好疼爱里面》免费看,年轻漂亮的女士护士内衣,妈妈醉酒后把我当爸爸电视剧

文章 > Python基础教程 > 详解python迭代循环和用户输入

详解python迭代循环和用户输入

头像

silencement

2019-06-28 10:57:323134浏览 · 0收藏 · 0评论

FOR(iteration) 循环

for 循环是 Python 中最常用的迭代机制。Python 中几乎所有的结构都能被 for 迭代。包括列表,元组,字典等。另一种常用的循环是 while 循环,但是 for 循环会是你最常见到的循环。

什么是 while 循环

while 循环会判断一个初始条件,条件成立则执行一次迭代,每次迭代完成后重新判断条件,如果成立则继续迭代,否则退出循环。

通用语法

# Set an initial condition.
game_active = True

# Set up the while loop.
while game_active:
    # Run the game.
    # At some point, the game ends and game_active will be set to False.
    #   When that happens, the loop will stop executing.
    
# Do anything else you want done after the loop runs.

每次循环前都要初始化一条判断为 true 的条件。

while 循环中包含条件判断。

条件判断为 true 则执行循环内代码,不断迭代,判断。

判断为 false 则退出循环。

示例

# The player's power starts out at 5.
power = 5

# The player is allowed to keep playing as long as their power is over 0.
while power > 0:
    print("You are still playing, because your power is %d." % power)
    # Your game code would go here, which includes challenges that make it
    #   possible to lose power.
    # We can represent that by just taking away from the power.
    power = power - 1
    
print("\nOh no, your power dropped to 0! Game Over.")

用户输入

在 Python 中你可以利用 input() 函数接受用户输入。函数可以接受一条提示信息,等待用户输入。

通用用法

# Get some input from the user.
variable = input('Please enter a value: ')
# Do something with the value that was entered.

示例

如下示例,提示用户输入名字,加入到名字列表中。

# Start with a list containing several names.
names = ['guido', 'tim', 'jesse']

# Ask the user for a name.
new_name = input("Please tell me someone I should know: ")

# Add the new name to our list.
names.append(new_name)

# Show that the name has been added to the list.
print(names)
关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

免费B站在线观看人数在哪儿找到| 坐在教授的根茎上写句子漫画图片| 按摩师把我添高潮了6次| 《XL司令》第一季动漫免费播放| 男人添女人荫道口视频| 蜜桃浏览器| 两个老头把我添高潮了| 俄罗斯少女2免费观看| 《性爽2》电影| 《魅魔妈妈》第1季动漫| 打扑牌不盖被子怎么办| 灭火宝贝高清完整版在线观看| 欧美大片PPT免费大全| 妈妈的绣感| 《请好好疼爱里面》免费观看| 双男主MV大片| 妈妈的朋友4| 破浪男女在线观看电影完整版| 我的青春谁做主在线 | 《性呻吟》伦理| CSGO高清大片免费播放器| 他扒开内裤把舌头伸进去| 黑科网 今日黑科独家爆料| 玉女桃花轻蜜粉是正规还是仿| 林柔柔在厨房被C高潮| 周翊然| 小天马| 《一滴都不许漏》何泽城林荫| 他的大手在秘密花园游走漫画| 美国性伦1980禁忌禁忌| 《性爽2》电影| 王蒙多| 主动把奶头放进男朋友嘴巴里| 《交换做爰》在线观看| 无码免费AV片在线观看| 丫头把腿开大让我添添| 女性三角毛毛区有片毛掉光正常吗| 免费观看B站刺激战场2023| 潮湿的体温2| 美国伦理〈欲奴3)| 妈妈叫我戴上避孕套英文