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

你可能感兴趣的文章
SpringBoot中集成Redis实现对redis中数据的解析和存储
查看>>
pthread_create导致的程序崩溃
查看>>
ptyhon POSIX
查看>>
public private protected default小结
查看>>
PublicCMS怎么用金蝶Apusic Application Server部署
查看>>
publish over ssh、 Kubernetes Continuous Deploy插件
查看>>
PubMed详解-ChatGPT4o作答
查看>>
Pubsub Extensions for Smack
查看>>
pulsar mq 单体验证demo, docker启动pulsar mq验证生产者消费者命令
查看>>
pulsar mq 学习使用,pulsar java客户端, spring boot pulsar , spring pulsarTemplate如何使用 pulsar4.0.0
查看>>
Pulsar mq 设置延迟消息模式 pulsar mq 发送延迟消息 pulsar如何发送消费延时消息
查看>>
Pulsar 游标回滚,移动偏移量测试
查看>>
pulsar开源消息队列_了解Pulsar---Pulsar工作笔记001
查看>>
Puppet 在大规模分布式系统中的性能优化策略有哪些?
查看>>
puppet 学习总结(1)——puppet 入门详解
查看>>
puppet 集中化管理PDF by 守住
查看>>
Puppet---自动化运维工具(进阶)
查看>>
puppeteer(三)常用API
查看>>
PyTorch 微调终极指南:第 2 部分 — 提高模型准确性
查看>>
pure css做的手机页面
查看>>