python中的三元操作符
来源:互联网 发布:期货软件怎么用 编辑:程序博客网 时间:2024/05/16 13:54
今天看廖大的教程,发现了python中原来也有三元操作符,之前接触过一点的Java中也有
今天特此记录一下
#比较俩数中比较小的一个:
a= 3
b = 8
small = (a if a < b else b)
print(small)
比较三个数中比较小的一个:
x ,y,z = 78,99,12
small = (x if x < y else y)
small = (z if small > z else small)
print(small)
比较三个数中最大的一个:
a,b,c = 78,64,92
big = (a if a > b else b)
big = (c if big < c else c)
print(big)
下面再写一种普通的写法:
比较三个数中最小的一个:
d,e,f=77,27,99if d < e: small = delse: small = eif small < f: small = smallelse: small = fprint(small)
如此对比看来三元操作符还是很简单的!!
阅读全文
0 0
- python中的三元操作符
- python中的三元操作符
- Python中的三元操作
- python中的三元操作符;assert断言
- python三元操作符
- python 三元操作符
- python中的三元运算符
- 7.python 三元操作符和断言
- python中的三元运算
- 三元操作符
- 三元操作符
- 三元操作符陷阱
- js 三元操作符
- 三元操作符
- javascript 三元操作符
- python三元运算符
- python 三元运算符
- python 中的三元表达式(三目运算符)
- Active Directory证书服务的安装与配置
- 编程之 最小的K个数 216 Kth Largest Element in an Array 378. Kth Smallest Element in a Sorted Matrix
- XenApp_XenDesktop_7.6实战篇之十四:XenDesktop虚拟桌面的交付
- promise兼容性问题
- XenServer 6.5实战系列之十三:图形界面安装Linux Redhat系统
- python中的三元操作符
- EasyUI学习笔记
- XenApp_XenDesktop_7.6实战篇之十五:StoreFront的配置
- [C++] Effective_C++_条款06
- XenApp_XenDesktop_7.6实战篇之十六:安装Virtual Delivery Agent For Windows Server OS
- 判断数据库里有没有要展示的表
- XenApp_XenDesktop_7.6实战篇之十七:XenApp应用程序交付
- Import Netscaler VPX10.5 to Hyper-V 2012R2
- Office 365系列之十三:Office 365管理员角色