TheRodMeister
9/27/2018 - 4:24 AM

## Check if String, Int, Or Float, return Bool

Three different functions to check if string, int, or float and return True or False

``````
print('str Checker: ')
#function that checks to see if input is string.
def checkString(inputType):
if inputType == str(inputType): #if input type str print true
print(True)
else:
print(False) #other wise print false

#call all functions to test
checkString('hello world')
checkString(20)
checkString(.0001)
checkString('hello' + 'hello')

#function that checks to see if input is int
def checkInt(inputType):
if inputType == str(inputType): #if input is str print false
print(False)
elif inputType == int(inputType): #if input is int print true
print(True)
elif inputType == float(inputType): #if input is float print false
print(False)

print('int Checker: ')
#call all functions to test

checkInt(20)
checkInt(.001)
checkInt('hello')

#function that checks to see if input is float
def checkFloat(inputType):
if inputType == str(inputType):
print(False)
elif inputType == int(inputType):
print(False)
elif inputType == float(inputType):
print(True)

print('Float Checker: ')

#call all functions to test
checkFloat(20)
checkFloat(.001)
checkFloat('hello')

``````
``````"C:\Python Practice Exercises\venv\Scripts\python.exe" "C:/Python Practice Exercises/Practice exercises one/Intro Hello world.py"
str Checker:
True
False
False
True
int Checker:
True
False
False
Float Checker:
False
True
False

Process finished with exit code 0
``````