7.python 三元操作符和断言
2015-08-25 14:45
411 查看
一、三元操作符
x,y = int(input('please input number1: ')),int(input('please input number2: '))print(x,y)
small = x if x < y else y
print(small)
二、断言(assert)
assert 这个关键字我们称之为断言,当这个关键字后边条件为假的时候,程序自动崩溃并抛出AssertionError的异常。例子:
assert 3 > 4
一般来说我们可以用Ta在程序中植入检查点,当需要确保程序中的某个条件一定为真才能让程序正常工作的话,assert关键字就非常有用了
相关文章推荐
- python数据类型——字典
- python练习
- python2.7.10安装配置
- python 流程控制
- Python的列表推导式学习
- windows32位安装MYSQL-python1.2.3
- [python]发送邮件(可带附件+转中文)
- python并行化介绍及使用 Pool
- python菜鸟日记8
- 超算上安装python+HTSeq+numpy+easy_install
- 使用Python实现Hadoop MapReduce程序
- pythonXXX云所有厂商
- python find file
- (转)python 计算代码行数以及相关知识点
- Python并发编程
- 【Python】[进程和线程]多进程,多线程,ThreadLocal,进程VS.线程,分布式进程
- Python中time和datetime模块对时间的操作
- Python 中 datetime时间模块学习
- Python 获取文件信息
- python类实例方法,类方法,类静态方法