流程控制

流程控制

一、分支结构

1、if else

x = int(input("please input x:"))
y = int(input("please input y:"))
if(not x>=90 and not y>=90):
    print("A")
else 
    print("B")

2、elifd 用法

if(a >=90):
    print("a>=90")
elif (a >=80):
    print("90>=a>=80")
else
    print("a<80")

三、for 循环
for 循环遍历序列,如一个列表或一个字符

语法:
for 参数 in 来源

for x in "abcd":
    print("hello world")

for x in "abcd":
    print(x,"hello world")


for x in [0,1,2,3,4,5,6]:
    print(x,"hello world")

rang[i,j[,步进值]]

for i in range(2,15,3):
    print (i)

结果

C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Administrator/PycharmProjects/test/test.py
2
5
8
11
14

Process finished with exit code 0 
s = ["hello", "haha", "gogo"]
for x in range(len(s)):
    print(x, s[x])

C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Administrator/PycharmProjects/test/test.py
0 hello
1 haha
2 gogo

Process finished with exit code 0
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 上一篇:《Python | list和while》 上篇文章中,介绍了while语句,这一章中,继续学习新的流程控...
    憨厚的老菜鸟阅读 4,357评论 3 3
  • 系列文章全部为本人的学习笔记,若有任何不妥之处,随时欢迎拍砖指正。如果你觉得我的文章对你有用,欢迎关注我,我们一起...
    我爱吃栗子啊阅读 6,306评论 1 9
  • 流程控制 目录:顺序结构分支循环循环嵌套控制循环的关键词 总会出现一种场景:要满足某个条件时,才去做一件事情。 ...
    Ansaxnsy阅读 4,300评论 0 1
  • 王小黑又被师傅张无德给暴打了一顿。 只是因为他昨天认真洗的碗。 中午师傅拿碗过去盛饭的时候,手滑了一下,把碗给打碎...
    一临阅读 3,793评论 7 3
  • 问题描述 app启动后大概有几秒白屏,才会显示首页,如下gif图 解决方法1 请查看以下3张图的标注图 1-最初c...
    昵称已被使用_阅读 14,836评论 34 18

友情链接更多精彩内容