0
Existence check in python
hey guys how can I define a function which checks if a digit exists in a number? ( I'm talking about integers. )
7 Antworten
+ 3
# is this what you are searching for?
def myfunc(num, digit):
if str(digit) in str(num):
return "Exist"
return "Does not exist"
print(myfunc(12345, 3))
+ 2
The simple way is to convert the int to a string. Then search for the digit in the string.
+ 1
Well yeah I got that thank y'all.
I meant how can we check if a digit exists in a number. For example whether 3 exists in 76567*5261788 or not. According to what you kind people said - which is true - we have to convert them into strings.
0
Did you mean the length of the intigers
0
do you mean check if a given digit exist within a number?
please give us an input and an output exemple to figure out what do you exactly mean.
0
"""I'm not very good in English, but I think that's what you mean.
"""
isinstance(5,int)
or
if int == type(5):
"do something"