简明的脚本语言------------运算符-----------求知Python

运算符

算术运算符

 简明的脚本语言------------运算符-----------求知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

 

关系运算符

    简明的脚本语言------------运算符-----------求知Python

代码:

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

赋值运算符

  简明的脚本语言------------运算符-----------求知Python

相关推荐