day 3
1,bool值类型只有两个值(true,false)
str int bool 三种数据类型之间的转化
a、str() int() bool() 本身是内置函数
str--->int a = "64363264" 元素必须是数字, 否则报错
str--->bool 空串是 false 不为空全部为true
int--->bool 0为false , 非0全部为true
bool-->int true是1 false 是0
bool--->str "true ","false"
2、比较运算符
== 比较两个对象的值是否相同
is 比较的是内存地址是否相同
看内存地址的方法 id(对象)
3、逻辑运算符 and or not
XandY,X为真, 值是Y,X为假,值是X
(在逻辑运算and 中取值取后边的)右图:
------------------------------------------------------------
Xor Y,X为真, 值就是X, X为假,值是Y
(or 中取值取前边)右图:
比较运算符优先级高于逻辑运算符
()> noy > and > or
如果优先级在同一级,从左往右依次执行
练习题:
8 and 6 6
0 and 8 0
6 or 56
0 or 7 7
7 or 6 and 8 7
7 or 6 and 8 and 9 7
7 or 6 and 0 and 9 7
or
a or b a为True 则返回a,(一个镇则为真)
a为False返回b
and
a 为True 则返回b
a为false则返回false(一个为假则起假)
not
ont True ----false
ont3 ---false
ont0----true
4, 算数运算符 + - * / %取余 ** 平方 // 取整
5, 成员运算符 in, not in
现在学的只有字符串 x in y, y中是否包含x
6, 赋值运算符
= += -= *= /= %= **= //=
复合赋值运算符
在python中这种对a进行加法之后再赋值给a的情况,我们叫做自加,常见的操作当然还有自减
a = 6
a +=1
a -=3
学到的内置函数
print()
input()
type()
int()
str()
bool()
小数据池: 只在str,int中存在的
a、小数据池作用:(为了节省内存而存在)
b、数据 -5 ---256 之间的值共用一个内存地址
c、str ,空 或者一位(包括特殊字符) 也是共用一个内存
d、如果多位并且包括特殊字符不共用内存
为空时,true
在python交互式时,变量可以直接输出,不用借助print