博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python学习---range/for/break/continue简单使用
阅读量:4315 次
发布时间:2019-06-06

本文共 916 字,大约阅读时间需要 3 分钟。

range的使用:注意,在python3中,交互模式下已经不显示了

for循环的使用

打印50-70

# 第一种方案for i in range(100):    if i <= 70 and i >= 45:   #注意这里使用的是 and/or/not  非java中的&&,||,!        print (i)# 第二种方案for i in range(50,71):    print (i)

break/continue的使用

exit_Flag = Falsefor i in range(100):    if i < 5:        continue    print("L_1:",i)    for j in range(10):        print("layer2:",j)        if j == 7:            exit_Flag=True            break    if exit_Flag:        break

用户登录小程序

_user="hhh"_pass="hello"count = 1while count <= 3:    username = input("Please input the username:")    password = input("Please input the password:")    if _pass == password and _user == username:        print("Welcome to BBT,", username)        break    else:        print()        print("Invalid username or password,you still have " + str(3 - count) + " times")    count += 1else:    print("Time out,~-~")

转载于:https://www.cnblogs.com/ftl1012/p/9381817.html

你可能感兴趣的文章
Python性能鸡汤
查看>>
android Manifest.xml选项
查看>>
Cookie/Session机制具体解释
查看>>
ATMEGA16 IOport相关汇总
查看>>
有意思的cmd命令
查看>>
js正則表達式语法
查看>>
Git学习系列-Git基本概念
查看>>
c#多个程序集使用app.config 的解决办法
查看>>
Linux+Apache+PHP+MySQL服务器环境配置(CentOS篇)
查看>>
Linux下获取本机IP地址的代码
查看>>
(C#)调用Webservice,提示远程服务器返回错误(500)内部服务器错误
查看>>
flex布局
查看>>
python-----python的文件操作
查看>>
java Graphics2d消除锯齿,使字体平滑显示
查看>>
控件中添加的成员变量value和control的区别
查看>>
Spring Boot Docker 实战
查看>>
Div Vertical Menu ver3
查看>>
Git简明操作
查看>>
InnoDB为什么要使用auto_Increment
查看>>
HDU 1087 Super Jumping! Jumping! Jumping!
查看>>