if not sky.has_key('blue'):
get_currently_compared_key # blue
elif not sky.has_key('cloud'):
get_currently_compared_key # cloud
In above code, I want to get ‘blue’ in if statement. Is there any useful method?
Edited 1: if sky == ‘blue’ -> if not sky == ‘blue’
Edited 2: if not sky.has_key(‘blue’)…
There’s no magic identifier that expands to
blueinside the consequent, if that’s what you mean,although.skyobviously has the value you’re afterEdit: I suppose you mean
sky != 'blue'instead ofnot sky == 'blue'. No, there’s no magic way to get to the values under comparison in the condition. Either type'blue'again or create a variable holding it outside the conditional:Edit 2: okay, so it’s
has_key. Still no magic. Note thathas_keyhas been deprecated for quite some time in favor of'blue' in sky(or'blue' not in sky).