2017-02-14 14:22:45 -05:00
|
|
|
# sets, see set_containment
|
2014-01-11 07:39:33 -05:00
|
|
|
for i in 1, 2:
|
2017-02-14 14:22:45 -05:00
|
|
|
for o in {1:2}, {1:2}.keys():
|
2020-09-23 22:03:30 -04:00
|
|
|
print("{} in {}: {}".format(i, str(o), i in o))
|
|
|
|
print("{} not in {}: {}".format(i, str(o), i not in o))
|
2014-01-11 07:39:33 -05:00
|
|
|
|
|
|
|
haystack = "supercalifragilistc"
|
2014-09-23 10:10:03 -04:00
|
|
|
for needle in [haystack[i:] for i in range(len(haystack))]:
|
2014-01-11 07:39:33 -05:00
|
|
|
print(needle, "in", haystack, "::", needle in haystack)
|
|
|
|
print(needle, "not in", haystack, "::", needle not in haystack)
|
|
|
|
print(haystack, "in", needle, "::", haystack in needle)
|
|
|
|
print(haystack, "not in", needle, "::", haystack not in needle)
|
2014-09-23 10:10:03 -04:00
|
|
|
for needle in [haystack[:i+1] for i in range(len(haystack))]:
|
2014-01-11 07:39:33 -05:00
|
|
|
print(needle, "in", haystack, "::", needle in haystack)
|
|
|
|
print(needle, "not in", haystack, "::", needle not in haystack)
|
|
|
|
print(haystack, "in", needle, "::", haystack in needle)
|
|
|
|
print(haystack, "not in", needle, "::", haystack not in needle)
|
|
|
|
|
2017-08-09 07:25:48 -04:00
|
|
|
# containment of bytes/ints in bytes
|
|
|
|
print(b'' in b'123')
|
|
|
|
print(b'0' in b'123', b'1' in b'123')
|
|
|
|
print(48 in b'123', 49 in b'123')
|
|
|
|
|
|
|
|
# containment of int in str is an error
|
|
|
|
try:
|
|
|
|
1 in '123'
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
|
|
|
|
2014-01-11 07:39:33 -05:00
|
|
|
# until here, the tests would work without the 'second attempt' iteration thing.
|
|
|
|
|
|
|
|
for i in 1, 2:
|
|
|
|
for o in [], [1], [1, 2]:
|
|
|
|
print("{} in {}: {}".format(i, o, i in o))
|
|
|
|
print("{} not in {}: {}".format(i, o, i not in o))
|