isinstance(n, int) # n = 9, Returns True / n = 5.5, Returns False
(1.23).is_integer() # Returns false
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)
N.is_integer()
#The isnumeric function can be used to determine a string is an integer or not!
#for example!
s = '5651'
if s.isnumeric():
print('True')
else:
print('False')
#i hope i helped you!
#Sorry for bad english!
# initalising strings
from multiprocessing.sharedctypes import Value
str1 = "10"
str2 = "FavTutor blogs"
str3 = "for10"
# creating a list of all the variables to check multiple cases
variables = [str1, str2, str3]
# declaring a flag for check
flag = True
for var in variables:
# Applying error - handling method
try:
# try converting to integer
int(var)
except ValueError:
flag = False
# flag check
if flag:
print("This is an integer")
else:
print("This is not an integer")
>>> 50.is_integer
SyntaxError: invalid syntax