How is the logical processing being done for strings like 'Dog' and 'Cat'
georgeryoung at gmail.com
Tue Oct 21 04:41:33 CEST 2008
On Oct 20, 9:41 pm, Sumitava Mukherjee <sm... at cognobytes.com> wrote:
> Hi all,
> I am a novice programmer in Python.
> Please could you explain me the results (regarding logical operators).
> I get this:
> >>> print bool('God' and 'Devil')
> [This is ok because (any) string is True,
Not quite so. Be careful with this. The empty string gets False:
print bool("") --> False
Any *non-empty* string gets True.
> so; (True and True) gives
> >>> print('God' and 'Devil')
> [This is what I don't get ]
> and for that matter,I also checked out this:
> >>> 01 and 10
Note that AND is a boolean operator, not a bit operator. If you want
to hack bits of an integer, use the "binary bitwise operators"
>>> 01 & 10
>>> 01 | 10
> What is python doing when we type in ('God' and 'Devil') or key in (01
> and 10) ?
More information about the Python-list