Jul
According to my book (byteofpython), the following command should output 'True'
>>>x = False; not y
but it is outputting false
>>>x = True; not y
is also outputting false
Am I doing something wrong? Is my book wrong? What's the problem? Any help would be appreciated. Thanks!
Answer:
This can be found on page #21 of the pdf available here:
http://www.ibiblio.org/swaroopch/byteofp…
This page is discussing boolean operators and expresssions.
It is kind of confusing, so we have the ability to do our own little tests to verify what they are trying to state (it all depends on what you have 'x' & 'y' initialized already)
>>> x = False
>>> y = False
>>> x; y
False
False
Just verifying x & y are false.
The 'NOT' operator, according to the book:
If x is True, it returns False. If x is False, it returns True.
x, in this case, can mean any variable.
>>> not x
True
>>> not y
True
'not' simply returns the opposite of the variable. In this case, since both variables were false, not'ing them gives us the opposite. Let's change the values to True and test again.
>>> x = True; y = True
>>> not x
False
>>> not y
False
Here, we get an understanding of what 'not' does. Now, let's look at what you have written.
>>>x = False; not y
This changes the value for 'x', but simply 'not' the 'y'. So, in your case, 'y' == True, so it will always return False. Changing the value of x will have no output.
I hope this clears things up.
Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList