Python编程-基础知识-条件判断
1. 简单的if/else条件判断
judge_flow.py
name = input("Please input name: ")
if name == 'master':
print('Hello Master')
password = input('Please input password: ')
if password == 'abc123':
print('Access granted.')
else:
print('Wrong password!')
else:
print('Invalid user!')
运行结果:
Please input name: david
Invalid user!
Please input name: master
Hello Master
Please input password: aaa
Wrong password!
Please input name: master
Hello Master
Please input password: abc123
Access granted.
2. 多项条件判断
elif statements
judge_flow_multiple.py
age = int(input("Input your age: "))
if age < 5:
print('Hi, Baby.')
elif age < 12:
print('Hi Child.')
elif age < 100:
print('Hi Man')
else:
print('Your Majesty')
运行结果:
Input your age: 3
Hi, Baby.
Input your age: 90
Hi Man
Input your age: 1000
Your Majesty
Python编程-基础知识-条件判断的更多相关文章
- python基础知识--条件判断和循环
一.输入输出 python怎么来接收用户输入呢,使用input函数,python2中使用raw_input,接收的是一个字符串,输出呢,第一个程序已经写的使用print,代码入下: 1 name=in ...
- Python入门基础之条件判断、循环、dict和set
Python之if语句 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,可以用if语句实现: age = 20 if age >= 18: print 'your age is ...
- 第2章 Python编程基础知识 第2.1节 简单的Python数据类型、变量赋值及输入输出
第三节 简单的Python数据类型.变量赋值及输入输出 Python是一门解释性语言,它的执行依赖于Python提供的执行环境,前面一章介绍了Python环境安装.WINDOWS系列Python编辑和 ...
- shell编程基础(3)条件判断语句
1,带参数的shellscript #this is program build 5.11 to test shell script ############ cxz ####### 5.11 ### ...
- python编程基础知识—字典
字典 在python中,字典是一系列键-值对,每个键都与一个值相关联,可使用键来访问相关联的值.与键相关联的值可以是数字.字符串.列表乃至字典,即可将任何python对象用在字典中的值. 在pytho ...
- python编程基础知识—列表(一)
1 列表 用[]来表示列表,并用逗号分隔其中的元素.如: B=['trek','cannondale','redline','specialized'] print(B) ['trek', 'cann ...
- Python编程-基础知识-python项目包和文件的管理以及如何引用相对路径的包和模块
目录 结构: core |____ __init__.py |____ basic |____ __init__.py |____ database |____ __init__. ...
- 第2章 Python编程基础知识目录
第2.1节 简单的Python数据类型.变量赋值及输入输出 第2.2节 Python的语句 第2.3节 Python运算符大全 老猿Python,跟老猿学Python! 博客地址:https://bl ...
- python编程基础知识—列表(二)
3操作列表 3.1 遍历整个列表 使用for循环 cars = ['bmw','audi','toyota','Jeep'] for i in cars: print(i) bmw audi toyo ...
随机推荐
- SQL Server 无日志文件附加数据库
CREATE DATABASE DBname ON (FILENAME = 'D:\SalesData\DBname_data.mdf') FOR ATTACH_REBUILD_LOG ; GO 简单 ...
- ZOJ 1940 Dungeon Master 三维BFS
Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- mySql---or和in的效率问题(和<=、>=、between之间的关系)
写在前面: 本文是直接拿取的别人的实验数据作参考,然后对数据作分析. 参考网友的测试数据结果: 在网上一直看到的是or和in的效率没啥区别,一直也感觉是这样,前几天刚好在看<mysql数据库开发 ...
- ServletActionContext.getRequest().getSession() 和 ActionContext.getContext().getSession()
ActionContext.getContext().getSession(); 这个方法获取的session是struts封装过的一个Map类型的session,只能调用put()方法缓存数据. S ...
- Oracle sql语句中(+)作用
select * from operator_info o, group_info g where o.group_id = g.group_id(+); 理解: + 表示补充,即哪个表有加号 ...
- SEEprog Serial EEPROM programmer
Features SEEprog is universal programmer of all types of serial EEPROMs in 8-pin package. SEEprog en ...
- MVC二级联动使用$.getJSON方法
本篇使用jQuery的$.getJSON()实现二级联动. □ View Models 1: namespace MvcApplication1.Models 2: { 3: public cla ...
- SimpleDateFormat in Java is not Thread-Safe Use Carefully
SimpleDateFormat in Java very common and used to format Date to String and parse String into Date i ...
- 撤销正在审核的app
一个app还未通过审核,但是新版本已经出来了,怎样才能撤销正在审核的app呢? 方法:在 是binary deatils里用 reject this binary.之后,即可以重新上传代码了.
- MyBatis+Spring SQL效率测试报告
1. 数据库结构 2. insert 测试 insert 的测试包括 1) 批量拼接values()插入 2) 有事务for循环插入 3) 无事务for循环插入 测试 SQL: <!-- 普通 ...