xxxxxxxxxx
if type(variable) == int or type(variable) == float:
isNumber = True
xxxxxxxxxx
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)
xxxxxxxxxx
var.isdigit()
#return true if all the chars in the string are numbers
#return false if not all the chars in the string are numbers
xxxxxxxxxx
myVariable = input('Enter a number')
if type(myVariable) == int or type(myVariable) == float:
# Do something
else:
print('The variable is not a number')
xxxxxxxxxx
>>> def hasNumbers(inputString):
return any(char.isdigit() for char in inputString)
>>> hasNumbers("I own 1 dog")
True
>>> hasNumbers("I own no dog")
False