Potential confusion combining != with or - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Potential confusion combining != with or (/thread-22102.html) Pages:
1
2
|
RE: Potential confusion combining != with or - Mark17 - Nov-04-2019 (Oct-31-2019, 07:21 AM)perfringo Wrote: buran explanation backed-up with Python docs (already referenced earlier): I didn't see these three posts until now. This is the sort of explanation I really wanted except I do not understand. Can you explain the odd, even, odd output in this example? RE: Potential confusion combining != with or - buran - Nov-04-2019 maybe this will help as it brakes line 3 into sub-steps lst = [1, 2, 3] for i in lst: print(f'i={i}') print(f"i % 2 --> {i % 2}") print(f"{i % 2} and 'odd' --> {i % 2 and 'odd'}") print(f"{i % 2 and 'odd'} or 'even' --> {i % 2 and 'odd' or 'even'}") print('-'*10)
|