> By the way, when I tried using
>     if selection_case is None:
>         ...
> It is not working as I expected it would output the same as in the code I
> have written


Not answering the original question but you can clearly distinguish between
True, False and None, as Justin has rightly pointed out.

In python None (
https://docs.python.org/2.7/c-api/none.html?highlight=none%20object) is
just a singleton, immutable object, meaning that there is only one instance
of None during a session of python interpreter(singleton) and it cannot be
changed(immutable).

So when you run python, there is always only one object None with no
methods to mutate it. Btw, this is the most precise definition of
immutability in python - objects that do not have any mutable methods
implemented for them are immutable, nothing more, nothing less. There is
not some* 'magic lock'* that prevent objects from changing in memory, it is
just the absence of methods that can mutate it.

So None just happens to be a convinience object, that can be  used for
implying the notion of an *empty* or *none* or *null* value.

Also note that, in python, variable names are just like stickers or labels
that you put on objects in memory. With different assignments you just move
around those labels.

Now let's talk about `None` and `booleans`.

The following values are considered false in python
<https://docs.python.org/2.7/library/stdtypes.html?highlight=booleans#truth-value-testing>
:

   - None
   - False
   - zero of any numeric type, for example, 0, 0L, 0.0, 0j.
   - any empty sequence, for example, '', (), [].
   - any empty mapping, for example, {}.
   - instances of user-defined classes, if the class defines a
   __nonzero__() or __len__() method, when that method returns the integer
   zero or bool value False.

All other values are considered true — so objects of many types are always
true.

Let's say you create a variable and set it to None.
*>>>* var = *None                                                      *

What you have done here is just created a new reference or "label" or
"sticker" on the `None` object im memory.


'None' will always resolve to false as boolean:
>>> *bool*(var)
False


But, we can still check if it is `None`
>>> var is *None*
True

Note that in the above, the is keyword just compares the memory address of
objects (oject identity)
is basically answers the question *"Do I have two names for the same
object?"*

This allows us to have three separate states of our variable either they
are None, or False, or True.

While using None and booleans togetther always remember to use is None to
first check if it is None or not. I would even to go out on the limb to say
that whenever a variable is set to None, in most cases use if var is None
instead of if not var.

Here's a more concrete example,
--------------------------------------------------------------------------------

# The goal here is to find that value and# save it for later use.

# We are dealing with a value# that can be either True or False.

# First, we assign `None` to our variablevalue_true_or_false = None
# Next, `value_true_or_false` variable is passed to# some function to
get the valuevalue_true_or_false =
some_func_to_get_value(value_true_or_false)


# At this point we want to save this value, but before saving it, # we
need to check if the function has 'filled in' our value.
# BAD (WILL FAIL)# Usually we are tempted to do this,if
value_true_or_false:  # Note: `if var` is more pythonic than `if var
== True`
    save(value_true_or_false)
# The above will work if setting_true_or_false is True,# but will NOT
save the value if it is False!

# GOOD (WILL WORK)# We want to save both the values either True or
False, whatever it is.# So the correct way to do this is:if
value_true_or_false is not None:
    save(value_true_or_false)

----------------------------------------------------------------------------------------------------------------------------
Hope that helps

- Alok


On Sat, Sep 24, 2016 at 3:55 AM, Justin Israel <justinisr...@gmail.com>
wrote:

> To be honest, there isn't enough context here for me to really understand
> what you are trying to do. I would need to see a small real example to
> better understand the logic you want to achieve.
> But the fact is that you can specifically check for "is None". The
> question is really how you want to use it to achieve some kind of goal
> here.
>
> On Sat, 24 Sep 2016, 4:34 AM yann19 <yangki...@gmail.com> wrote:
>
>> Initially I had defined my selection_case to be False instead of None as
>> I am not so sure which of the two I should put.
>> There has been a function before this test() code I wrote that checks for
>> selection. If there are no selections, it will return None. If there are
>> selections, it will then check if the selections fulfills the nodetype
>> criteria as defined in wihin sel_custom and sel_orig.
>>
>> Hence my usage of:
>>     if selection_case:
>>         ...
>>     else:
>>         ...
>>
>> In cases like this, should I just put it as selection_case = False
>> instead?
>>
>> By the way, when I tried using
>>     if selection_case is None:
>>         ...
>>
>> It is not working as I expected it would output the same as in the code I
>> have written
>>
>> --
>> 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 python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/python_inside_maya/54b3089d-5e19-43d4-b520-
>> fb7595632142%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/54b3089d-5e19-43d4-b520-fb7595632142%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/CAPGFgA1-9oPa1%3DE-9bXOXyo%
> 2BqnOmPp0PvV8ULnt-jnS4m7D2kQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1-9oPa1%3DE-9bXOXyo%2BqnOmPp0PvV8ULnt-jnS4m7D2kQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



--

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMRDwkGbH5cZc7LZ9j4vNOU9Gwz50UbvPYYtBKo3G1dKxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to