这些运算符是什么意思 (** , ^ , %,//)? [英] What do these operators mean (** , ^ , %, //)?
本文介绍了这些运算符是什么意思 (** , ^ , %,//)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了标准的+
、-
、*
和/
操作符;但是这些是什么意思 (**
, ^
, %
, //
) ?
^
运算符怎么样?
%
in x%m
返回正常的余数模数,但仅当 m <;x
,为什么会这样?%
有什么作用?
//
运算符怎么样?它有什么作用?
解决方案
**
:求幂^
:异或(按位)%
:模数//
:除以整数结果(丢弃余数)
Other than the standard +
, -
, *
and /
operators; but what does these mean (**
, ^
, %
, //
) ?
>>> 9+float(2) # addition
11.0
>>> 9-float(2) # subtraction
7.0
>>> 9*float(2) # multiplication
18.0
>>> 9/float(2) # division
4.5
>>>
>>> 9**float(2) # This looks like a square, (i.e. power 2)
81.0
>>> 9**float(3) # So ** is equivalent to `math.pow(x,p)` ?
729.0
How about the ^
operator?
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
%
in x%m
returns a normal remainder modulus, but only if m < x
, why is that so? What does %
do?
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
How about the //
operator? what does it do?
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
解决方案
**
: exponentiation^
: exclusive-or (bitwise)%
: modulus//
: divide with integral result (discard remainder)
这篇关于这些运算符是什么意思 (** , ^ , %,//)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文