博客
关于我
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/

你可能感兴趣的文章
Nginx配置参数中文说明
查看>>
Nginx配置好ssl,但$_SERVER[‘HTTPS‘]取不到值
查看>>
Nginx配置如何一键生成
查看>>
Nginx配置实例-负载均衡实例:平均访问多台服务器
查看>>
NIFI1.21.0通过Postgresql11的CDC逻辑复制槽实现_指定表多表增量同步_增删改数据分发及删除数据实时同步_通过分页解决变更记录过大问题_02----大数据之Nifi工作笔记0054
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置binlog_使用处理器抓取binlog数据_实际操作01---大数据之Nifi工作笔记0040
查看>>
NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置数据路由_实现数据插入数据到目标数据库_实际操作03---大数据之Nifi工作笔记0042
查看>>
NIFI同步MySql数据_到SqlServer_错误_驱动程序无法通过使用安全套接字层(SSL)加密与SQL Server_Navicat连接SqlServer---大数据之Nifi工作笔记0047
查看>>
Nifi同步过程中报错create_time字段找不到_实际目标表和源表中没有这个字段---大数据之Nifi工作笔记0066
查看>>
NIFI大数据进阶_离线同步MySql数据到HDFS_02_实际操作_splitjson处理器_puthdfs处理器_querydatabasetable处理器---大数据之Nifi工作笔记0030
查看>>
NIFI大数据进阶_连接与关系_设置数据流负载均衡_设置背压_设置展现弯曲_介绍以及实际操作---大数据之Nifi工作笔记0027
查看>>
NIFI数据库同步_多表_特定表同时同步_实际操作_MySqlToMysql_可推广到其他数据库_Postgresql_Hbase_SqlServer等----大数据之Nifi工作笔记0053
查看>>
NIFI汉化_替换logo_二次开发_Idea编译NIFI最新源码_详细过程记录_全解析_Maven编译NIFI避坑指南001---大数据之Nifi工作笔记0068
查看>>
NIFI集群_内存溢出_CPU占用100%修复_GC overhead limit exceeded_NIFI: out of memory error ---大数据之Nifi工作笔记0017
查看>>
NIH发布包含10600张CT图像数据库 为AI算法测试铺路
查看>>
Nim游戏
查看>>
NIO ByteBuffer实现原理
查看>>
Nio ByteBuffer组件读写指针切换原理与常用方法
查看>>
NIO Selector实现原理
查看>>
nio 中channel和buffer的基本使用
查看>>