简明的脚本语言------------运算符-----------求知Python
运算符
算术运算符
代码:
a=21; b=10; c=0; c=a+b; print("a+b的值为: ",c); c=a-b; print("a-b的值为: ",c); c=a*b; print("a*b的值为: ",c); c=a/b; print("a/b的值为: ",c); #取余 c=a%b; print("a%b的值为: ",c); #幂次方 a=2; b=3; c=a**b; print("a的b次幂为: ",c); #取整 a=10; b=5; c=a//b; print("a除b,取整: ",c);
运行结果:
runfile('D:/新建文件夹/WinPython-64bit-3.3.5.9/settings/.spyder2-py3/My Python Code/key.py', wdir='D:/新建文件夹/WinPython-64bit-3.3.5.9/settings/.spyder2-py3/My Python Code') a+b的值为: 31 a-b的值为: 11 a*b的值为: 210 a/b的值为: 2.1 a+b的值为: 1 a的b次幂为: 8 a除b,取整: 2
关系运算符
代码:
a=21 b=10 c=0 if(a==b): print("a==b"); else: print("a!=b"); if(a!=b): print("a!=b"); else: print("a==b"); if(a>b): print("a>b"); else: print("a<=b"); if(a<b): print("a<b"); else: print("a>=b"); if(a>=b): print("a>=b"); else: print("a<b"); if(a<=b): print("a<=b"); else: print("a>b");
代码结果:
runfile('D:/新建文件夹/WinPython-64bit-3.3.5.9/settings/.spyder2-py3/My Python Code/key.py', wdir='D:/新建文件夹/WinPython-64bit-3.3.5.9/settings/.spyder2-py3/My Python Code') a!=b a!=b a>b a>=b a>=b a>b
赋值运算符
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16