2017-02-14 19:22:45 +00:00
|
|
|
# sets, see set_containment
|
2014-01-11 12:39:33 +00:00
|
|
|
for i in 1, 2:
|
2017-02-14 19:22:45 +00:00
|
|
|
for o in {1:2}, {1:2}.keys():
|
2020-09-24 03:03:30 +01:00
|
|
|
print("{} in {}: {}".format(i, str(o), i in o))
|
|
|
|
print("{} not in {}: {}".format(i, str(o), i not in o))
|
2014-01-11 12:39:33 +00:00
|
|
|
|
|
|
|
haystack = "supercalifragilistc"
|
2014-09-23 15:10:03 +01:00
|
|
|
for needle in [haystack[i:] for i in range(len(haystack))]:
|
2014-01-11 12:39:33 +00: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 15:10:03 +01:00
|
|
|
for needle in [haystack[:i+1] for i in range(len(haystack))]:
|
2014-01-11 12:39:33 +00: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 12:25:48 +01: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 12:39:33 +00: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))
|