I tried to find the available methods but couldn't find it. There is no contains
. Should I use index
? I just want to know if the item exists, don't need the index of it.
Method #1: Using any() any function is used to perform this task. It just tests one by one if the element is present as the tuple element. If the element is present, true is returned else false is returned.
You can use set. issubset or set. issuperset to check if every element in one tuple or list is in other.
1. Tuple Membership Test. We can test if an item exists in a tuple or not, using the keyword in .
You use in
.
if element in thetuple:
#whatever you want to do.
if "word" in str(tuple):
# You can convert the tuple to str too
i has the same problem and only worked to me after the convert str()
Be careful with that: return Oops. use Set: d= {...}
def simha():
d = ('this_is_valid')
b = 'valid'
if b in d:
print("Oops!!!!!")
simha()
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