Python 条件判断的缩写方法

yipeiwu_com6年前Python基础
return (1==1) ? "is easy" : "my god" //C#中的用法

其实,在Python中,是这样写的:

print (1==2) and 'Fool' or 'Not bad'


输出结果:
Not bad
                       

相关文章

python 简单的绘图工具turtle使用详解

python 简单的绘图工具turtle使用详解

目录 1. 画布(canvas)   1.1 设置画布大小 2. 画笔   2.1 画笔的状态   2....

Python ValueError: invalid literal for int() with base 10 实用解决方法

今天在写爬虫程序的时候由于要翻页,做除法分页的时候出现了 复制代码 代码如下: totalCount = '100' totalPage = int(totalCount)/20 Va...

python类的实例化问题解决

python类的实例化问题解决

类的实例化问题解决 运行结果: line 21, in <module> s=speaker('ken',10,'aaa') TypeError: __init__(...

pygame编写音乐播放器的实现代码示例

pygame编写音乐播放器的实现代码示例

1、准备工作 ide:pycharm python:3.7 三方包:pygame、pyinstaller、mutagen 几首mp3格式的歌 2、开始 2.1 设计说明 1、包含...

Python multiprocessing多进程原理与应用示例

本文实例讲述了Python multiprocessing多进程原理与应用。分享给大家供大家参考,具体如下: multiprocessing包是Python中的多进程管理包,可以利用mu...