While "piz" in "pizza"
throws an error, 'z' in "pizza"
works just fine. Julia treats String
s as a sequence of Char
s, and in
is consistently used to check if an element is present in a collection.
Python’s in
actually treats strings as special. (1,2) in (1,2,3)
seems just as natural as "piz" in "pizza"
, but in
only searches for substrings, not subsequences in general. I think the reason Julia’s in(::String, ::String)
throws an error is more because many new users had used Python and expect this special treatment of strings. Habits are often mistaken for intuition.
This of course is not relevant to the merits of making occursin
or contains
infix operators, it’s just a comment on the error for in(::String, ::String)
.