(value)
return not not value
Attempt to convert different type of values to a meaningful boolean
Attempt to convert different type of values to a meaningful boolean
Attempt to convert different type of values to a meaningful boolean
def is_affirmative(value):
    """
    Attempt to convert different type of values to a meaningful boolean
    """
    # try string cast
    if isinstance(value, str):
        return value.lower() in {'yes', 'true', '1', 'y', 'on'}

    # use object's implementation of `__bool__`, it's faster than cast.
    # None -> False, 0 -> False, 1 -> True, etc.
    return not not value
def is_affirmative ( value ) : # try string cast if isinstance ( value , str ) : return value . lower ( ) in { 'yes' , 'true' , '1' , 'y' , 'on' } # use object's implementation of `__bool__`, it's faster than cast. # None -> False, 0 -> False, 1 -> True, etc. return not not value