python运算符讲解
#软件工具:Sublime Text
#因为变量名相同,执行前把之前的语句注释掉再执行
#运算符讲解
#1.加号运算符:+
a = 11
b = 22
c = a + b
print(c)
#结果为33
a = "11"
b = "22"
c = a + b
print(c)
#结果为1122
#2.减号运算符:-
#只能对数值类型相减,字符串类型就不行,会报错
a = 11
b = 22
c = a - b
print(c)
#结果为-11
a = "11"
b = "22"
c = a - b
print(c)
#结果报错,字符串类型不支持相减的操作
#3.乘号运算符:*
a = 11
b = 2
c = a * b
print(c)
#结果为22
#字符串类型与数值型相乘
c = "=" * 30
print(c)
#可用于区分打印数据
#4.除法运算符:/
#只能对数值类型相减,字符串类型就不行,会报错
a = 11
b = 2
c = a / b
print(c)
#结果为5.5
#5.取整除://
#只能对数值类型相减,字符串类型就不行,会报错
a = 11
b = 2
c = a // b
print(c)
#结果为5
#6.取余:%
#只能对数值类型相减,字符串类型就不行,会报错
a = 11
b = 2
c = a % b
print(c)
#结果为1
#7.幂运算:**
#只能对数值类型相减,字符串类型就不行,会报错
a = 2
b = 4
c = a ** b
print(c)
#结果为16
#8.简写形式:+=、-=、*=、/=、%=、**=、//=
#a+=1等价于a=a+1
a = 3
a += 4#等价于a=a+4
print(a)
#结果为7