Custom Search

Sunday, February 13, 2011

python boolean Operations and or not

python boolean Operations and or not

============ or =================

>>>
>>> a = 0
>>> b = 10
>>> c = a or b
>>> c
10

>>> ----------------------

>>> a = 5
>>> b = 10
>>> c = a or b
>>> c
5

>>> ---------------------

>>> a = None
>>> b = 10
>>> c = a or b
>>> c
10

>>> ---------------------

>>> a = ""
>>> b = 10
>>> c = a or b
>>> c
10


************************** Equal To

>>> a = None
>>> b = 10
>>> if not a:
... c = b
... else:
... c = a
...
>>>
>>> c
10

>>> ---------------------

>>> a = 5
>>> b = 10
>>> if not a:
... c = b
... else:
... c = a
...
>>>
>>> c
5




=============== and =================

>>>
>>> a = 5
>>> b = 10
>>> c = a and b
>>> c
10

>>> ------------------------

>>> a = 0
>>> b = 10
>>> c = a and b
>>> c
0

>>> ------------------------

>>> a = None
>>> b = 10
>>> c = a and b
>>> c

>>> ------------------------

>>> a = ""
>>> b = 10
>>> c = a and b
>>> c
''
>>>


==================================

More.....

No comments:

Post a Comment