![]() |
if, or, in, else in 1 line - how to make it work? - 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: if, or, in, else in 1 line - how to make it work? (/thread-21013.html) |
if, or, in, else in 1 line - how to make it work? - zarize - Sep-10-2019 hi guys, i would like to learn how to make "OR" function in sentence below: My goal is to get returned Blue if found substring "Blue" or "blue" in string color= "Blue" if 'blue' in description else "yellow"i tried to do: color= "Blue" if 'blue' or 'Blue' in description else "yellow"but it doesn't work #edit I figured it out: color= "Blue" if 'Blue' in description or "blue" in description else "yellow" RE: if, or, in, else in 1 line - how to make it work? - buran - Sep-10-2019 color= "Blue" if 'blue' in description.lower() else "yellow" RE: if, or, in, else in 1 line - how to make it work? - zarize - Sep-10-2019 thanks for your solution :) good to know about .lower() |