定义Python运算符:列表

时间:2014-06-18 02:36:24

标签: python operators

通过Zed Shaw学习Python的艰难之路有一个未被定义为练习的运算符列表,我在尝试找到它们的定义/目的时遇到了麻烦。网页。

这是我到目前为止所拥有的:

+   : addition/concatenation 
-   : subtraction
*   : multiplication 
**  : exponenttiation
/   : division
//  : floor division :: digits after the decimal place are removed
%   : string type flag?
<   : less than
>   : greater than 
<=  : less than / equal 
>=  : greater than / equal
==  : absolute equality
!=  : not equal
<>  : old not equal -- apparently phased out, use above != now
()  : ________________________
[]  : ________________________
{}  : ________________________
@   : decorators, maybe matrix multiplication in 3.5 future release
'   : ________________________
:   : ________________________
.   : this is generally used as a modifying/linking element to property/subproperty
=   : equality
;   : ________________________
+=  : duality in operation, successively :: x = x + 1 >> x += 1
-=  : "                                " :: x = x - 1 >> x -= 1
*=  : "                                " :: x = x * 1 >> x *= 1
/=  : "                                " :: x = x / 1 >> x /= 1 
//= : Floor division and assigns a value, performs floor division on operators and assign value to the left operand
%=  : Modulus AND assignment operator, it takes modulus using two operands and assign the result to the left operand : c%=a == c = c % a
**= : Exponent AND assignment operator: Performs exponential (power) calculation on operators and assigns value to the left operand : c **= a == c ** a , so c to the exponent of a

我确定这些定义并不完整而且措辞可能很差,所以如果你想对以前的定义进行修正,无论如何,我主要是试图找出那些我的定义。尚未完成 - 上面有空行

我尝试过的链接:Python Operators 1 || Python Operators 2 || Python 3.0 Operators || 2.7.7 Operator Precedence ||

1 个答案:

答案 0 :(得分:2)

%是模数。 3 % 2 == 1。您也可以在格式化字符串时使用它,但作为运算符,它是模数。对于格式化字符串,首选myString.format()。

()是函数调用或一般表达式中的优先顺序。例如,f(x)(3 * (1 + 2))。它调用对象的__call__方法。它还会创建一个元组文字,但前提是元组中至少有一个逗号。例如(4,)

[]正在编制索引 - 它允许您通过__getitem____setitem__方法按索引选择容器。 [1,2,3,4,5,6][2] == 3。它还会创建一个列表。

{}构造一个集合或字典,具体取决于上下文。

@用于装饰器,不用于矩阵乘法。

'是一个引用,相当于"

:用于列表切片,并表示代码块。 (例如在函数,错误处理上下文或循环中)

除非您想在一行中放置多个语句,否则不会使用

;,但出于可读性目的,不鼓励这样做。

除此之外,我认为你的定义或多或少是正确的。

相关问题