-1

I was trying to create a function so I thought of trying to make type function and here is what I tried:

def value_type(X):
    if X == int:
        print ("integer")
    elif X == str:
        print ("string")
    else: 
        print ("floating-point number")

Now I know what the mistake is here. It is that int and str are function not a value.

But the question is, what should I use instead of them?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Sami Shtewi
  • 1
  • 1
  • 2
  • You can in fact check if a type equals `int` or `str`. You can use `type(v) == int`, or `type(v) is int`, or `isinstance(v, int)`. There are differences between them which you should try to understand. – Tom Karzes Sep 13 '20 at 09:16

1 Answers1

0
def valu(x):
if type(x)==int:
    print("integer")
elif type(x)==str:
    print("string")
else:
    print("floting point")


valu()