2
'he' in 'hello'
>>>True


for i in 'hello':
  print(i,end = ' ')
>>>'h' 'e' 'l' 'l' 'o'
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 2
    Because that's how the language is defined. In the latter case, `in` is not an operator but is rather part of the `for` statement. It's just two different uses of the same English word. – CryptoFool Feb 19 '21 at 06:27
  • it is not assignment, it is iterating over string. Where is the assignment? – Nagmat Feb 19 '21 at 06:27
  • 3
    Does this answer your question? [In Python, how is the in operator implemented to work? Does it use the next() method of the iterators?](https://stackoverflow.com/questions/53542860/in-python-how-is-the-in-operator-implemented-to-work-does-it-use-the-next-me) – python_user Feb 19 '21 at 06:27

1 Answers1

0

On the first case in is used to check if it is included on second string, while the second in is a part of for loop for iterating over a string.

Nagmat
  • 373
  • 4
  • 14