Discuss 'and' does not work as I thought in the Python Programming forum on Dev Shed. 'and' does not work as I thought Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Posts: 24
Time spent in forums: 13 h 14 m 44 sec
Reputation Power: 0
'and' does not work as I thought
Code:
space1 = 'X'
space2 = 'O'
space3 = 'X'
if space1 and space2 and space3 == 'X':
print 'space1 and space2 and space3 all equal X'
else: print 'space1 and space2 and space3 do not all equal X'
I would expect this code to print that it space1 2 and 3 do not equal X. How would I make this code print space1 2 and 3 do not equal x?
Posts: 24
Time spent in forums: 13 h 14 m 44 sec
Reputation Power: 0
Code:
space1 = 'X'
space2 = 'O'
space3 = 'X'
if space1 == 'X' and space2 == 'X' and space3 == 'X':
print 'space1 and space2 and space3 all equal X'
else: print 'space1 and space2 and space3 do not all equal X'
Ok this works. Thanks for putting it into perspective for me.