truefalse
# None,0, and empty strings/lists/dicts/tuples/sets all evaluate to False.
# All other values are True
not true=false
not false=truetrue and false 与运算(and)
true or false 或运算(or)
true+true=2false+false=0bool()函数
# 返回值为true 或 falseeg:bool(-5) #truebool([]) #false
==!= 相等不等
><>=<= 可以连用 eg:1<2<3=true
is == 的区别
# is判断的是地址
# ==判断的是值
eg: a=[1,2,3,4]
b = a
b is a #true
b == a #true
a=[1,2,3,4]
b=[1,2,3,4]
b is a #false
b == a #true
# 字符串操作
+ 字符串相加 eg:a ="hello" b ="world" c = a + b c ="hello world"
# 若不是变量'+'可以省略 eg:"hello""world"="hello world"
#字符串可以被看作为数组 eg:"hello world"[0]='h'len()函数 求字符串长度 eg:len("hello")=5F字符串(f-string)
#要在字符串中插入变量的值,可在前引号前加上字母f,再将要插入的变量放在{}内。
eg:age =19 name = cui
f"my name is {name}"= my name is cui
f"my name length is {len(name)}"= my name length is 3
None
# None是python中的一个特殊的常量,表示一个空的对象。
# 数据为空并不代表是空对象,例如空列表:[],等都不是None。
# None有自己的数据类型NontType,你可以将None赋值给任意对象,但是不能创建一个NoneType对象。
# None只能用is判断,不能用==判断
eg:a =print("hello")
a is None =true
b={}
b is None =false
b is false=true