Python-assignment-operators-example
提供:Dev Guides
Python割り当て演算子の例
変数aが10を保持し、変数bが20を保持すると仮定します-
Operator | Description | Example |
---|---|---|
= | Assigns values from right side operands to left side operand | c = a + b assigns value of a + b into c |
+= Add AND | It adds right operand to the left operand and assign the result to left operand | c += a is equivalent to c = c + a |
-= Subtract AND | It subtracts right operand from the left operand and assign the result to left operand | c -= a is equivalent to c = c - a |
*= Multiply AND | It multiplies right operand with the left operand and assign the result to left operand | c *= a is equivalent to c = c * a |
/= Divide AND | It divides left operand with the right operand and assign the result to left operand | c/= a is equivalent to c = c/a |
%= Modulus AND | It takes modulus using two operands and assign the result to left operand | c %= a is equivalent to c = c % a |
**= Exponent AND | Performs exponential (power) calculation on operators and assign value to the left operand | c **= a is equivalent to c = c * *a |
//= Floor Division | It performs floor division on operators and assign value to the left operand | c//= a is equivalent to c = c//a |
例
変数aが10を保持し、変数bが20を保持すると仮定します-
上記のプログラムを実行すると、次の結果が生成されます-