I've this code:
url='http://mybeautifulurl.com'
('h' or 'f') in url[0:4] #This is True
('f' or 'h') in url[0:4] #This is False
I'm just trying to understand why the 'or' operator seems to evaluate just the first condition.
I've this code:
url='http://mybeautifulurl.com'
('h' or 'f') in url[0:4] #This is True
('f' or 'h') in url[0:4] #This is False
I'm just trying to understand why the 'or' operator seems to evaluate just the first condition.
This or
returns the first element if it evaluates to true (as a bool) and the second one otherwise... it's is usually applied to set default values.
This way, 'h' or 'f'
is simply 'h'
and 'f' or 'h'
is simply 'f'
.
You can achieve what you want with something like:
any(x in url[:4] for x in ['h', 'f'])