
浮点数和整数运算实例
注意:整数运算结果仍然为整数。但是只要运算的数中存在浮点数,结果就变为浮点数。
1 + 2 # ==> 整数 31.0 + 2.0 # ==> 浮点数 3.01 + 2.0 # ==> 浮点数 3.0
定义字符串
上面讲了字符串可以用''或者""括起来表示。如果字符串本身包含这些引号怎么办?这时,如果包含单引号,我们就用双引号括起来,同样包含双引号,就用单引号括起来。
"Learn 'Python3' in python3m"'Learn "Python3" in python3m'
布尔运算
与运算:只有两个布尔值都为 True 时,计算结果才为 True。
True and True # ==> TrueTrue and False # ==> FalseFalse and True # ==> FalseFalse and False # ==> False
或运算:只要有一个布尔值为 True,计算结果就是 True。
True or True # ==> TrueTrue or False # ==> TrueFalse or True # ==> TrueFalse or False # ==> False
非运算:把True变为False,或者把False变为True:
not True # ==> Falsenot False # ==> True
此外,还有不常用的复数,如1 + 2j、 1.1 + 2.2j