Different types of Print function like Print(type(variable_name))

https://www.codecademy.com/courses/learn-python-3/lessons/python-control-flow/exercises/boolean-variables?action=resume_content_item

It seems like they skip the “print (type(variable_name))” I don’t recall learning different types of print. What does the “type” actually do when run print function? I’m lost. Thanks in advance for your help.

There is only one print() function, which always does the same thing: it first evaluates the expression within its parentheses, and then sends a string representation of the returned value to the default i/o device (usually your screen).

In this case, the expression is type(), which is is itself a function: It returns the type (i.e., int, str, float, etc.) of the argument passed when it is called.

print(type(3.14))
print(type('abc'))
my_boolean = (5 > 2)
print(my_boolean)
print(type(my_boolean))

Output:

<class 'float'>
<class 'str'>
True
<class 'bool'>

type is a type, the type of types :^)

>>> type(type)
<class 'type'>
2 Likes