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

你可能感兴趣的文章
PL/SQL 存储函数和过程
查看>>
query简单入门到精通细节 - (六)Jquery效果之“淡入与淡出”
查看>>
PL/SQL提示“ORA-01722:无效数字,将无效数字查找出来
查看>>
PL/sql语法单元
查看>>
PL/SQL连接远程服务器数据库,出现ORA-12154: TNS: 无法解析指定的连接标识符。
查看>>
pl/sql锁
查看>>
PL2303 Windows 10 驱动项目常见问题解决方案
查看>>
QueryPerformanceCounter与QueryPerformanceFrequency
查看>>
Plaid.com的监控系统如何实现与9600多家金融机构的集成
查看>>
Plain Stock Prediction:基于RNN的股票价格预测工具
查看>>
platform_driver与file_operations两种方法开发led驱动
查看>>
PlatON共识方案详解:应用CBFT共识协议,提高共识效率
查看>>
QueryDict和模型表知识补充
查看>>
Querybase 使用与安装教程
查看>>
Playwright与Selenium的对比:谁是更适合你的自动化测试工具?
查看>>
quarz设置定时器任务的有效时间段_定时器?你知道有几种实现方式吗?
查看>>
PLC、DCS、SCADA的选型
查看>>
PLC中的电子凸轮的简单介绍
查看>>
PLC发展详解-ChatGPT4o作答+匹尔西
查看>>
PLC探针有什么用
查看>>