Membership testing with count() and in

Another means of searching is to count() matching elements:

>>> w.count("the")
2

If you just want to test for membership, you can use the in operator:

>>> 37 in [1, 78, 9, 37, 34, 53]
True

A non-membership with not in:

>>> 78 not in [1, 78, 9, 37, 34, 53]
False
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset