File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ Operators
2121* Slicing (``s[n:m] ``, ``s[n:] ``, ``s[:m] ``)
2222* Comparisons (``== ``, ``!= ``)
2323* Augmented assignment (``s1 += s2 ``)
24+ * Containment (``s1 in s2 ``)
2425
2526.. _str-methods :
2627
Original file line number Diff line number Diff line change 8484 error_kind = ERR_MAGIC ,
8585)
8686
87+ # item in str
88+ binary_op (
89+ name = "in" ,
90+ arg_types = [str_rprimitive , str_rprimitive ],
91+ return_type = c_int_rprimitive ,
92+ c_function_name = "PyUnicode_Contains" ,
93+ error_kind = ERR_NEG_INT ,
94+ truncated_type = bool_rprimitive ,
95+ ordering = [1 , 0 ],
96+ )
97+
8798# str.join(obj)
8899method_op (
89100 name = "join" ,
Original file line number Diff line number Diff line change @@ -140,11 +140,24 @@ def test_partition() -> None:
140140 with assertRaises(ValueError, "empty separator"):
141141 rpartition(s_partition, "")
142142
143+ def contains(s: str, o: str) -> bool:
144+ return o in s
145+
143146def getitem(s: str, index: int) -> str:
144147 return s[index]
145148
146149s = "abc"
147150
151+ def test_contains() -> None:
152+ assert contains(s, "a") is True
153+ assert contains(s, "abc") is True
154+ assert contains(s, "Hello") is False
155+ assert contains(s, "bc") is True
156+ assert contains(s, "abcd") is False
157+ assert contains(s, "bb") is False
158+ assert contains(s, "") is True
159+ assert contains(s, " ") is False
160+
148161def test_getitem() -> None:
149162 assert getitem(s, 0) == "a"
150163 assert getitem(s, 1) == "b"
You can’t perform that action at this time.
0 commit comments