Python Forum

Full Version: if, or, in, else in 1 line - how to make it work?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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"
color= "Blue" if 'blue' in description.lower() else "yellow"
thanks for your solution :) good to know about .lower()