04 - 运算符
笔记
1. 运算符
1.1 运算符的概念
1.2 运算符的分类
2. 算术运算符
-
加法运算符 +
a = 1.0 + 2 b = 1 + 2 c = 'hello'+'world' d = 'hello'+' '+ 'world' e = 'hello',' ', 'world' print(a,b,c,d,e) #3.0 3 helloworld hello world ('hello', ' ', 'world')
-
减法运算符 -
a = 5 - 2 # b = 'python' - 'y' #TypeError: unsupported operand type(s) for -: 'str' and 'str' c = 5 - True print(a,c) # 3 4
-
乘法运算符 *
a = 5 * 2 b = 'a' * 5 # c = 'a '* 'b' #TypeError: can't multiply sequence by non-int of type 'str' print(a,b