Mr. Who Mr. Who - 9 months ago 123
Python Question

and logical operation on python 2.7

I use python 2.7.12 on Ubuntu 16.04, I have this in some part of my code:

for i in np.arange(0,max+1):
...
if i != 1 and i != max :
t_try[i] = (C_[i])/(2.0*D)


but I get different results with this changes:

for i in np.arange(0,max+1):
...
if (i != 1) and (i != max) :
t_try[i] = (C_[i])/(2.0*D)


or

for i in np.arange(0,max+1):
...
if (i != 1 and i != max) :
t_try[i] = (C_[i])/(2.0*D)


I failed to see what is the problem.

Answer Source

This is for the precedence of operators: https://docs.python.org/2/reference/expressions.html or, and are prevalent over ==, =!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download