博客
关于我
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 反向代理 MinIO 及 ruoyi-vue-pro 配置 MinIO 详解
查看>>
nginx 反向代理 转发请求时,有时好有时没反应,产生原因及解决
查看>>
Nginx 反向代理解决跨域问题
查看>>
Nginx 反向代理配置去除前缀
查看>>
nginx 后端获取真实ip
查看>>
Nginx 多端口配置和访问异常问题的排查与优化
查看>>
Nginx 如何代理转发传递真实 ip 地址?
查看>>
Nginx 学习总结(16)—— 动静分离、压缩、缓存、黑白名单、性能等内容温习
查看>>
Nginx 学习总结(17)—— 8 个免费开源 Nginx 管理系统,轻松管理 Nginx 站点配置
查看>>
Nginx 学习(一):Nginx 下载和启动
查看>>
nginx 常用指令配置总结
查看>>
Nginx 常用配置清单
查看>>
nginx 常用配置记录
查看>>
nginx 开启ssl模块 [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx
查看>>
Nginx 我们必须知道的那些事
查看>>
Nginx 的 proxy_pass 使用简介
查看>>
Nginx 的配置文件中的 keepalive 介绍
查看>>
Nginx 结合 consul 实现动态负载均衡
查看>>
Nginx 负载均衡与权重配置解析
查看>>
Nginx 负载均衡详解
查看>>