num = int(input('Enter a number: '))
if num > 0:
    print('The number is positive')
elif num < 0:
    print('The number is negative')
else:
    print('The number is zero')
 
x == y x 等于y
x < y x小于y
x > y x大于y
x >= y x大于或等于y
x <= y x小于或等于y
x != y x不等于y
x is y x和y是同一个对象
x is not y x和y是不同的对象
x in y x是容器(如序列) y的成员
x not in y x不是容器(如序列) y的成员
同时使用多个比较运算符,如0 < age < 100
布尔运算符and,or,not
 
断言
工作原理类似这样:
if not condition:
    rash program
在错误条件出现时就崩溃胜过以后再崩溃
可以添加assert语句充当检查点
>>> age = 10
>>> assert 0 < age < 100
>>> age = -1
>>> assert 0 < age < 100
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AssertionError
还可以在后面加一个字符串,对断言加以说明
>>> age = -1
>>> assert 0 < age < 100, 'The age must be realistic'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AssertionError: The age must be realistic
 
 

最新文章

  1. navicat连接虚拟机(centos)中的mysql
  2. Entity Framework 实体框架的形成之旅--为基础类库接口增加单元测试,对基类接口进行正确性校验(10)
  3. jquermobile 安装
  4. python entrypoint
  5. 一:解决VirtualBox只能安装32位系统的问题
  6. xml架构管理器
  7. 百度地图API简单使用
  8. sharepoint 2010 页面添加footer方法 custom footer for sharepoint 2010 master page
  9. java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
  10. el和jstl
  11. 简单实用的日志类CLog (Python版)
  12. 判断小数点位数不超过2位的JS代码和在删除确认框里面插JS代码
  13. 核心动画 CAAnimation 进阶
  14. CodeForces 620E New Year Tree
  15. 使用Github Page鼓励自己每日编程
  16. Python argparse用法
  17. Python实现的各种机器学习算法
  18. 利用Python半自动化生成Nessus报告
  19. Subway (树中心 + 树hash)
  20. 下载,和scp上传问题

热门文章

  1. FZU1989 AntiAC —— 字符串
  2. SpringBoot2.0之整合ActiveMQ(发布订阅模式)
  3. 9.1 NOIP普及组试题精解(2)
  4. BZOJ 1640 [Usaco2007 Nov]Best Cow Line 队列变换:贪心【字典序最小】
  5. BZOJ 1201 [HNOI2005]数三角形:枚举 + 前缀和
  6. L91
  7. install docker
  8. Nginx均衡负载配置
  9. 【算法模板】Binary Search 二分查找
  10. bzoj 1202 [HNOI2005]狡猾的商人——带偏移量的并查集