File tree 3 files changed +25
-0
lines changed
3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ Operators
21
21
* Slicing (``s[n:m] ``, ``s[n:] ``, ``s[:m] ``)
22
22
* Comparisons (``== ``, ``!= ``)
23
23
* Augmented assignment (``s1 += s2 ``)
24
+ * Containment (``s1 in s2 ``)
24
25
25
26
.. _str-methods :
26
27
Original file line number Diff line number Diff line change 84
84
error_kind = ERR_MAGIC ,
85
85
)
86
86
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
+
87
98
# str.join(obj)
88
99
method_op (
89
100
name = "join" ,
Original file line number Diff line number Diff line change @@ -140,11 +140,24 @@ def test_partition() -> None:
140
140
with assertRaises(ValueError, "empty separator"):
141
141
rpartition(s_partition, "")
142
142
143
+ def contains(s: str, o: str) -> bool:
144
+ return o in s
145
+
143
146
def getitem(s: str, index: int) -> str:
144
147
return s[index]
145
148
146
149
s = "abc"
147
150
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
+
148
161
def test_getitem() -> None:
149
162
assert getitem(s, 0) == "a"
150
163
assert getitem(s, 1) == "b"
You can’t perform that action at this time.
0 commit comments