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!
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!
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.