In python, I'm trying to create a program which checks if 'numbers' are in a string, but I seem to get an error. Here's my code:
numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
test = input()
print(test)
if numbers in test:
print("numbers")
Here's my error:
TypeError: 'in <string>' requires string as left operand, not list
I tried changing numbers into numbers = "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"
which is basically removed the []
but this didn't work either. Hope I can get an answer; thanks :)
Use built-in any() function:
numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
s = input()
test = any(n in s for n in numbers)
print(test)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With