My answer is maybe out of topic, but you could also use if or if not, which
makes things easier to read, i think (although it's probably a personal
point of view). I don't know if there is a big difference in python between
!= and is not, i guess they probably call a very similar code under the
hood, but i do know that it makes a huge difference to have a code easy to
read and to maintain ! So maybe you should just go for the easier to
maintain instead of going for the faster. If you want to do faster code,
maybe python is not the best choice.
I find
if rx and ry and rz:
easier to read than
if rx is not None and ry is not None and rz is not None
in your example, you could even do :
if all(x for x in (rx, ry, rz)):
print 'do things'
that you can extrapolate to :
if all((rx, ry, rz)):
print 'do things'
(i didn't test it, so i may have done some errors, but you get the idea ;-)
What is great with python is that if you think something would be easier to
read with the syntax you have in mind, this syntax probably works !
And anyway, i am not a developer, so maybe what i say is complete bullshit,
so is anyone has a different point of view, feel free to answer ^_^
Le lundi 25 juillet 2016 20:51:33 UTC+1, Andres Weber a écrit :
>
> Pretty succinct explanation over here which covers it nicely. Mainly one
> is just actual equality versus class/instance identity. Try not to use is
> not for things where you're trying to compare direct values.
> http://stackoverflow.com/questions/2209755/python-operation-vs-is-not
>
>
>
> On Monday, July 25, 2016 at 12:45:38 PM UTC-4, likage wrote:
>>
>> I am wondering if anyone can tell me when it is best to use *is* or *is
>> not* over *==* or *!=*
>>
>> I have this line of code:
>> if (rx != None) and (ry != None) and (rz != None):
>>
>> and I am told that it will be better to write it this way instead:
>> if (rx is not None) and (ry is not None) and (rz is not None):
>>
>> Both method will gives the same result not?
>> But why *is/is not *preferred over *!=/==?*
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/c49f3041-9f11-47e1-995c-e6eef0515d5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.