python学习-5 python基础-2 条件语句(if的简单用法2---elif)
1.if的基本语句
if条件:
内部代码块
else:
。。。。。。。。
print(‘。。。。。。。’)
2.if语句支持嵌套
if条件:
内部代码块
if条件:
内部代码块
else:
。。。。。。。。
print(‘。。。。。。。’)
3.elif
vip = input('请输入会员级别:')
if vip == "":
print('欢迎五级高级会员光临!')
elif vip == "":
print('欢迎三级高级会员光临!')
elif vip == "一级初级会员":
print('欢迎一级初级会员光临!')
else:
print("您是会员吗!")
输出结果:
请输入会员级别:5
欢迎五级高级会员光临! Process finished with exit code 0
3. pass
代表占位,不会执行。
vip = input('请输入会员级别:')
if vip == "":
print('欢迎五级高级会员光临!')
elif vip == "":
print('欢迎三级高级会员光临!')
elif vip == "一级初级会员":
print('欢迎一级初级会员光临!')
pass
pass
else:
print("您是会员吗!")
输出结果:
请输入会员级别:0
您是会员吗! Process finished with exit code 0
4.字符串
引号引起来的统称字符串。 例如: name = 'aaa'
name = "aaa"
name ='''aaa'''
name = """aaa"""
加法
a1 = "a"
a2 = "b"
a3 = a1 + a2 # a3 = "a"+"b"
输出结果就是ab
乘法:
a1 = "a"
a2 = a1 * 10
a2就是把a1输出10次
数字的加减乘除是一样的。
加+
减-
乘*
除/
平方** 如:4**4 # 4的4次方
取余% 如:39%8 #获取39除以8得到的余数
取商// 如:42//8 #获取42除以8的商
一个小例子:判断奇数偶数
a = int(input("请输入一个整数:"))
b = a % 2
if b == 0:
print("偶数")
else:
print("奇数")
输入1,结果:
请输入一个整数:1
奇数 Process finished with exit code 0
python学习-5 python基础-2 条件语句(if的简单用法2---elif)的更多相关文章
- python学习笔记(三)--条件语句
Python 条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. Python 编程中 if 语句用于控制程序的执行,基本形式为: if 判断条 ...
- Python学习笔记(三)——条件语句、循环语句
注:需注意代码的缩进格式 注:需注意代码的缩进格式 注:需注意代码的缩进格式 Python 与其他语言最大的区别就是,Python 的代码块不使用大括号 {} 来控制类,函数以及其他逻辑判断.pyth ...
- Python基础之条件语句和循环
条件语句 Python中的条件语句分为 if ...else . if ...elif...else 以及if ...else 的嵌套使用: username = input('请输入您的用户名:' ...
- Python基础、条件语句和基本数据类型
1. 第一句python - 后缀名是可以是任意? - 导入模块时,如果不是.py文件 ==> 以后文件后缀名是 .py 2. 两种执行方式 python解释器 py文件路径 python 进入 ...
- 孤荷凌寒自学python第十四天python代码的书写规范与条件语句及判断条件式
孤荷凌寒自学python第十四天python代码的书写规范与条件语句及判断条件式 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 在我学习过的所有语言中,对VB系的语言比较喜欢,而对C系和J系 ...
- Python学习day16-模块基础
<!doctype html>day16 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...
- Python学习day05 - Python基础(3) 格式化输出和基本运算符
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- python学习日记(基础数据类型及其方法01)
数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...
- Python学习day12-函数基础(2)
<!doctype html>day12博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { pos ...
- Python学习day11-函数基础(1)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
随机推荐
- scrapy框架之基础
一.安装scrapy 安装失败看博客>>>scrapy安装失败解决方案 pip install wheel pip install twisted pip install pywin ...
- oracle insert into 多条数据
mysql : insert into tablename (column1,column2) values ('aa','bb'), ('dd','cc'), ('ee','ff'); oracle ...
- Flask 四种响应类型
1 直接返回字符串 可以返回状态码 @app.route('/testresponse', methods=['GET', 'POST']) def testresponse(): return &q ...
- Shiro RememberMe 1.2.4远程代码执行漏洞-详细分析
本文首发于先知: https://xz.aliyun.com/t/6493 0x01.漏洞复现 环境配置 https://github.com/Medicean/VulApps/tree/master ...
- Linux设备驱动程序 之 per-cpu变量
数组形式 支持SMP的现代操作系统使用每个cpu上的数据,对于给定的处理器其数据是唯一的:一般来说,每个cpu的数据存放在一个数组中,数组总的每一项对应着系统上的一个存在的处理器:按当前处理器号确定这 ...
- arcgis python 参数验证
import arcpy class ToolValidator(object): """Class for validating a tool's parameter ...
- CodeWar打怪升级-Python篇
1. The goal of this exercise is to convert a string to a new string where each character in the new ...
- hashMap 底层原理+LinkedHashMap 底层原理+常见面试题
1.源码 java1.7 hashMap 底层实现是数组+链表 java1.8 对上面进行优化 数组+链表+红黑树 2.hashmap 是怎么保存数据的. 在hashmap 中有这样一个结构 ...
- 陷门函数Trapdoor Function
陷门函数:正向计算是很容易的,但若要有效的执行反向计算则必须要知道一些secret/knowledge/trapdoor(知识?),也称为伪随机置换,可用于构造公钥密码系统. 若 f 为陷门函数,则 ...
- PyToune:一款类Keras的PyTorch框架
PyToune is a Keras-like framework for PyTorch and handles much of the boilerplating code needed to t ...