text 检查String,Int或Float是否返回Bool

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 检查String,Int或Float是否返回Bool相关的知识,希望对你有一定的参考价值。


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

以上是关于text 检查String,Int或Float是否返回Bool的主要内容,如果未能解决你的问题,请参考以下文章

在 VC++ Float 数据类型值中,如何检查字符串或特殊字符是不是没有混合

PHP 检查int或string变量是否为奇数

返回string,float或int的C ++函数

Return 不适用于 float 或 int,但适用于 string?

Java不同类型字符转换String/int/Float/////

Python,确定字符串是否应转换为Int或Float