tes python jika string adalah int
'16'.isdigit()
>>>True
'3.14'.isdigit()
>>>False
'Some text'.isdigit()
>>>False
Yvant2000
'16'.isdigit()
>>>True
'3.14'.isdigit()
>>>False
'Some text'.isdigit()
>>>False
(1.23).is_integer() # Returns false
if type(variable) == int or type(variable) == float:
isNumber = True
str = input("Enter any value: ")
if str.isdigit():
print("User input is an Integer ")
else:
print("User input is string ")
colors = [11, 34.1, 98.2, 43, 45.1, 54, 54]
for x in colors:
if int(x) == x:
print(x)
#or
if isinstance(x, int):
print(x)
'3'.isdigit()
True
'276'.isdigit()
True
'Bob276'.isdigit()
False
# The definition below interger will be flaged "True" as well as float.
def isfloat(num):
try:
float(num)
return True
except ValueError:
return False
print(isfloat('s12'))
False
print(isfloat('1.123'))
True
print(isfloat('456'))
True