Reputation: 75
I am writing a program with python to find if a number is present as a set in another number
for example:
if the number, a = '123456789010234
and I have to find if '4567'
is present in a or not.
Upvotes: 0
Views: 620
Reputation: 15872
If you are receiving both the numbers as strings:
a = '123456789010234'
b = '4567'
print(True if b in a else False)
If you are receiving as int
s, convert to string and check with in
operator.
If you need to check whether the strings are integer at all, or need to handle negative integers, you need to use try-except
.
Upvotes: 2
Reputation: 7214
Here you go:
if '123456789010234'.find('4567') > 0:
print ("Found!")
else:
print("Not Found!")
#Found!
if '123456789010234'.find('4d567') > 0:
print ("Found!")
else:
print("Not Found!")
#Not Found!
Upvotes: 2
Reputation: 4510
If a
is a string
you can just do this:
a = '123456789010234'
value = '4567'
if value in a:
print(f'Value {value} present in {a}')
else:
print(f'Value {value} not present in {a}')
Upvotes: 2
Reputation: 19264
Try using in
, if both are integers:
str(num) in str(a)
>>> a = 123456789010234
>>> num = 4567
>>> str(num) in str(a)
True
Upvotes: 3