博客
关于我
Python教程——8. 运算符
阅读量:52 次
发布时间:2019-02-25

本文共 2256 字,大约阅读时间需要 7 分钟。

Python ????????????????????

??? Python ??????????????????????????????????????????????????????????????????????????????

?????

?????=?????????? Python ??=?????????????????????????????

x = 1x = x + 1

???????=?????? 1 ????? x???? x + 1 ???????? x??? x ???? 2?

????????????????????????????????????

a = b = c = 4

???????a?b ? c ????? 4????????????????

?????

?????????????????????????????????????? +?-?*?/?// ? %????

a = 10b = 11c = 12add = a + b + csub = c - amult = a * bdiv = c / 3power = a ** 2

???????????????????????????????????? Python 3 ??/ ?????????????? // ????????????

?????

???????????????????????? and?or ? not??????????????True ? False??????????? if ? while?????????

print(True and True)   # ??: Trueprint(True and False)  # ??: Falseprint(False and True)  # ??: Falseprint(False and False)  # ??: False

??????????????????????????????????????????

?????

?????????????????????????????? <?<=?>?>=?== ? !=????

print(3 < 4)        # ??: Trueprint(4 == 3)        # ??: Falseprint(4 >= 3)        # ??: True

????????????????????????????????????????????????? TypeError ???

???????

??????? is ? is not ??????????????????????????????

print(None is None)      # ??: Trueprint(True is True)       # ??: Trueprint([] is [])          # ??: Falseprint("Python" is "Python")  # ??: True

is ?????????????? is not ???????????

?????

????? in ? not in ???????????????????????????

items = ("coin", "book", "pencil", "spoon", "paper")print("coin" in items)    # ??: Trueprint("bowl" not in items)  # ??: True

??????????????????????????

?????

????????????????????? exp1 if condition else exp2?????? True???? exp1????? exp2????

age = 31adult = True if age >= 18 else Falseprint(adult)   # ??: True

?????????????? if ???????

?????

??????? ~?^?&?<< ? >>?????????????????????

print(~7)        # ??: -8print(6 & 3)     # ??: 2print(6 | 3)     # ??: 7print(6 ^ 3)     # ??: 5print(6 << 1)    # ??: 12print(6 >> 1)    # ??: 3

????????????????????????????????

??????

???????????????????????????

print(3 + 5 * 5)    # ??: 28print((3 + 5) * 5)    # ??: 40

?????????????????????????????

????

???????????????????????

print(9 / 3 * 3)    # ??: 9print(2 ** 3 * 5)    # ??: 40

????????????????? 9 / 3???? 3?

??

??????? Python ???????????????????????????????????????????????????????????????

转载地址:http://ibk.baihongyu.com/

你可能感兴趣的文章
Postgresql中PL/pgSQL的游标、自定义函数、存储过程的使用
查看>>
SpringBoot中集成XXL-JOB分布式任务调度平台,轻量级、低侵入实现定时任务
查看>>
Postgresql中的表结构和数据同步/数据传输到Mysql
查看>>
Postgresql中自增主键序列的使用以及数据传输时提示:错误:关系“xxx_xx_xx_seq“不存在
查看>>
SpringBoot中集成websocket后WebSocketServer中注入mapper为空
查看>>
postgreSQL入门命令
查看>>
PostgreSQL删除数据库报"ERROR: There is 1 other session using the database."
查看>>
Qt开发——爱情公寓人事管理系统
查看>>
Qt开发——文件下载软件
查看>>
PostgreSQL和Oracle两种数据库有啥区别?如何选择?
查看>>
Qt开发——多线程网络时间服务器端
查看>>
Postgresql在Windows中使用pg_dump实现数据库(指定表)的导出与导入
查看>>
PostgreSQL在何处处理 sql查询之四
查看>>
postgresql基本使用
查看>>
PostgreSQL学习总结(10)—— PostgreSQL 数据库体系架构
查看>>
PostgreSQL学习总结(11)—— PostgreSQL 常用的高可用集群方案
查看>>
Qt开发——多线程网络时间客户端
查看>>
PostgreSQL学习总结(13)—— PostgreSQL 15.8 如何成就数据库性能王者?
查看>>
PostgreSQL学习总结(13)—— PostgreSQL 目录结构与配置文件 postgresql.conf 详解
查看>>
PostgreSQL学习总结(1)—— PostgreSQL 入门简介与安装
查看>>