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

你可能感兴趣的文章
python与c语言混合编程_你试过C语言和Python一起混合编程吗?两者相加不是已经无敌了!...
查看>>
python与excel
查看>>
Python与Excel的完美邂逅:深入浅出,手把手教你轻松玩转Excel数据操作
查看>>
python与flask_Python编程中flask的简介与简单使用
查看>>
python与图灵机器人交互(WXPY版本)
查看>>
python与运算符_python运算符
查看>>
python两个列表获取交集,并集,差集
查看>>
python两个字典合并,两个list合并
查看>>
Python两个版本共存时,命令行升级pip
查看>>
Python两个版本共存时,怎么验证是否安装成功 scrapy
查看>>
Python两个版本共存时,通过pip安装Scrapy
查看>>
python两组变量的相关关系散点图_变量是什么?变量间的两种关系——函数关系和相关关系(小学版)...
查看>>
Python中 pass语句的作用
查看>>
python中 urllib, urllib2, httplib, httplib2 几个库的区别
查看>>
python中 yaml库 & json库 & xmltodict库使用
查看>>
python中 将你的名字转化成为二进制并输出
查看>>
Python中*args 和**kwargs的用法
查看>>
Python中*args 和**kwargs的用法
查看>>
Python中*args和**kwargs的使用
查看>>
python中0、1、True、False、if条件
查看>>