I would like to create the check condition string is string number or not so, how I can do in python
x = "String"
y = "12"
if x is string:
print("this is string")
if y is string:
print("this is not string")
I would like to create the check condition string is string number or not so, how I can do in python
x = "String"
y = "12"
if x is string:
print("this is string")
if y is string:
print("this is not string")
You could try something like this:
array = ["String", "12"]
for item in array:
try:
int(item)
print(f"{item} is not string")
except:
print(f"{item} is string")
You can use .isdigit()
method to fulfill this.
x = "String"
y = "12"
if not(x.isdigit()):
print("this is string")
if y.isdigit():
print("this is not string")
Output:
this is string
this is not string