I am trying to understand in
operator's usage in Python.
Is there any difference between the following cases?
Case 1:
a = "Hello"
b = "Help"
b[0] in {a[0]} #case1
>> True
Case 2:
a = "Hello"
b = "Help"
b[0] in a[0] #case2
>> True
Though the outputs are same, I wanted to understand the difference between these two.
The first one is a set object with the first letter of
a
in it, plus the period. It is a sequence type thatin
can operate on.The second is a string with a single character in it. It is also a sequence type and the
in
operator can operate on it as well. The second one has no period in it.