>>> print(type(float)==type(str))
True
Why is it true?
The function type did the following task:
With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.class.
str and float are built-in data types of python. So your code works like this:
print(type(str)) # <class 'type'>
print(type(float)) # <class 'type'>
If you want to get the desired result, you can use the following code:
s = "test"
f = 3.0
print(type(s)==type(f)) # false
This happens because type(float) and type(str) are "type" objects
If you need to verify the type of a float value you can do something like this
float_value = 10.3
print(type(float_value) == float) # True
Another example with a string:
string_value = "hi"
print(type(string_value) == str) # True
floatandstrare types in Python, so bothtype(float)andtype(str)result intype(the type of all type objects in Python).type(float)andtype(str)and see what they are?