0

How can I make an if-else statement that classifies if the data that I have inputted is str, int, or float?

data = input('Enter a data: ')

What will I do next?

Thank you for your help!

Vennison
  • 13
  • 4
  • Does this answer your question? [What's the canonical way to check for type in Python?](https://stackoverflow.com/questions/152580/whats-the-canonical-way-to-check-for-type-in-python) – DDomen Feb 10 '21 at 11:59

1 Answers1

0

Code is straight forward for this:

def getType(data) -> str:
  return type(data).__name__

data = input('Enter a data: ')
print(f'data type = {getType(data)}')


# and then make your if-else statements

if(getType(data) is 'str'):
  print("it's string  ")

# or you can also do

if(type(data) is float):
  print("it's float ")


# so on ...

For reference, see this link.

Shyam Mittal
  • 188
  • 2
  • 9