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画图并导出图片格式的文件

如下所示: from turtle import* import turtle setup(800,700,300,50) penup() seth(90) fd(100) seth...

基于Python3.6+splinter实现自动抢火车票

本文实例为大家分享了python实现自动抢火车票,供大家参考,具体内容如下 splinter使用 首先介绍一下splinter使用: plinter.brower是一个开源工具,通过Py...

Tensorflow获取张量Tensor的具体维数实例

获取Tensor的维数 >>> import tensorflow as tf >>> tf.__version__ '1.2.0-rc1'...

SublimeText 2编译python出错的解决方法(The system cannot find the file specified)

[Error 2] The system cannot find the file specified 解决方法:1.环境变量path添加:C:\Python32\Tools\Scrip...

详解Python中find()方法的使用

 find()方法判断字符串str,如果起始索引beg和结束end索引能找到在字符串或字符串的一个子串中。 语法 以下是find()方法的语法: str.find(str,...