Return the type of a given value

Write a function using if statements that takes a value, and returns the type of that particular value. Example:

which_type(2) == 'integer'
which_type("cookies, now!") == 'string'
which_type(False) == 'boolean'
which_type(42.0) == 'float'

Hint: Be mindful of control flow. Remember that booleans in python are tricky.

Test Cases

test type boolean - Run Test

def test_type_boolean():
    assert which_type(True) == 'boolean'

test type float - Run Test

def test_type_float():
    assert which_type(3.14) == 'float'

test type int - Run Test

def test_type_int():
    assert which_type(42) == 'integer'

test type string - Run Test

def test_type_string():
    assert which_type('squirrel') == 'string'

Solution 1

def which_type(val):
    if isinstance(val, str):
        return 'string'
    elif isinstance(val, bool):
        return 'boolean'
    elif isinstance(val, int):
        return 'integer'
    elif isinstance(val, float):
        return 'float'
def which_type(val): pass