xxxxxxxxxx
isinstance(n, int) # n = 9, Returns True / n = 5.5, Returns False
xxxxxxxxxx
name = "Bob"
age = 23
if(type(name) != str):
print("Name is not string!")
if(type(age) != int):
print("Age is not int!")
# Alternative
if(not isinstance(name, str)):
print("Name is not string!")
if(not isinstance(age, int)):
print("Age is not int!")
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
str = input("Enter any value: ")
if str.isdigit():
print("User input is an Integer ")
else:
print("User input is string ")
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
#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!