1.复数(complex)是数学中的概念,复数有事不和虚部部分,用j或J表示虚数部分。
如:10+5j X8-7J
2.布尔值(bool)python中True表示真,False表示假,通常用来判断条件是否成立。
print(bool(-1)) #True
print(bool("abc")) #True
print(bool(0)) #False
print(bool("")) #False
'''
真(True):非零数字、非零对象。如bool(-1)、bool("abc")结果均为True
假(False):数字零、空对象、None。如bool(0)、bool("")、bool(None)均为False
其中空对象包括:None、空字符串、空列表、空元组、空字典等(现在你只需要了解知道有这些东西,后面会学到的)
'''
3.逻辑运算符(not and or)
not:非:not x,如果x为True,则返回False,如果x为False,则返回True
and:与:x and y,如果x为True,则返回y值,x为False,返回y值
or:或:如果x为True,则返回False,如果x为False,则返回True
print(-1 or 1) #-13
print("ab" and 0) #0
print(not 4) #False
'''
(1):-1和1均为True。因此or运算时,从左到右遇到第一个逻辑为True的值是-1,因此返回-1
(2):"ab"的逻辑值为True因此and运算时,因返回0
(3):4的逻辑值为True,因此(not 4)返回False
4.成员运算符(in not in)
in:如果元素在指定的序列中,测返回True,否则返回False
not in :如果元素不在指定的序列中,返回True,否则返回False
num=[1,2,3]
print(1 in num) #True
print("x" not in x) #True
'''
因为整型1在num中所以返回True
因为字符串"x"不在num中所以not in 返回True
'''