python幂运算运算符为_python学习20200508算数运算符、比较运算符和赋值运算符

算数运算符

+ - * /  //(整除)  %(取余)  ** 幂

比三个数那个最大

num1 = input("请输入第一个数字:")

num2 = input("请输入第二个数字:")

num3 = input("请输入第三个数字:")

if num1 > num2 > num3 :

print("最大的值是:",num1,"最小的值是:",num3)

elif  num1 >num3 >num2:

print("最大的值是:",num1,"最小的值是:",num2)

elif  num2 >num1 >num3:

print("最大的值是:",num2,"最小的值是:",num3)

elif  num2 >num3 >num1:

print("最大的值是:",num2,"最小的值是:",num1)

elif  num3 > num1 >num2:

print("最大的值是:",num3,"最小的值是:",num2)

elif   num3 >num2 > num1:

print("最大的值是:",num3,"最小的值是:",num1)

比较运算符                >    <   >=   <=    ==(判断是否等于,一个=是赋值,==才是判断是否相等)   !=(不等于)    true  false

nummax = 0

num1 = int(input("请输入第一个数字:"))

num2 = int(input("请输入第二个数字:"))

num3 = int(input("请输入第三个数字:"))

if num1 > nummax :

nummax = num1

if num2 > nummax :

nummax = num2

if num3 > nummax:

nummax = num3

print("最大的数是:",nummax)

else:

nummax = num2

print("最大的数是:",nummax)

else:

if num3 > nummax:

nummax = num3

print("最大的数是:",nummax)

else:

nummax = num1

print("最大的数是:",nummax)

else:

if num2 > nummax :

nummax = num2

if num3 > nummax:

nummax = num3

print("最大的数是:",nummax)

else:

nummax = num2

print("最大的数是:",nummax)

else :

if num3 > nummax:

nummax = num3

print("最大的数是:",nummax)

else:

nummax = nummax

print("最大的数是:",nummax)

num = 1   #赋值运算符             =    +=   -=   /=  *=  //=    %=   **=

num += 2    #等价于   num = num +2

num -=2     #等价于   num = num -2

num *=2     #等价于   num = num *2

num /=2     #等价于   num = num /2

num//=2     #等价于   num = num //2

%=          #求余

**=         #幂

逻辑运算符:  not  and  or  注意逻辑运算符短路原则

and          两个条件都正确,结果才正确

> 5 >3 and 6>3

True

>>> 5> 2  and 6> 7

False

5> 4 and 8> 9

False

or               两个条件有一个正确,结果就正确

not            不

not  5>6

True

优先级加小括号

表达式

1+2

操作数和运算符组合语句或代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值