I came across with the code syntax d //= 2
where d is a variable. This is not a part of any loop, I don't quite get the expression.
Can anybody enlighten me please?
When a variable is assigned a value in Python, the variable does not store the absolute value directly. Instead, Python creates a new reference to an object representing that value. For example, the line a = 1 assigns the value 1 to the variable a .
The == operator compares the value or equality of two objects, whereas the Python is operator checks whether two variables point to the same object in memory. In the vast majority of cases, this means you should use the equality operators == and !=
The assignment operator, denoted by the “=” symbol, is the operator that is used to assign values to variables in Python. The line x=1 takes the known value, 1, and assigns that value to the variable with name “x”. After executing this line, this number will be stored into this variable.
In that case the float value containing variable may contain same data but reason behind is to mathematical rules. The only two value are consider after the point & remaining are value get neglected. so the we get two different addresses of the same data containing variables.
//
is a floor division operator. The =
beside it means to operate on the variable "in-place". It's similar to the +=
and *=
operators, if you've seen those before, except for this is with division.
Suppose I have a variable called d
. I set it's value to 65
, like this.
>>> d = 65
Calling d //= 2
will divide d
by 2, and then assign that result to d. Since, d // 2
is 32 (32.5, but with the decimal part taken off), d
becomes 32:
>>> d //= 2
>>> d
32
It's the same as calling d = d // 2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With