CBSE Class 11 Computer Science Question 22 of 42

Practice Paper — Question 4

Back to all questions
4
Question

Question 22

Explain the membership operators in String.

Answer

Python offers two membership operators for checking whether a particular character exists in the given string or not. These operators are 'in' and 'not in'.

'in' operator — It returns true if a character/substring exits in the given string.

'not in' operator — It returns true if a character/substring does not exist in the given string.

To use membership operator in strings, it is required that both the operands used should be of string type, i.e., <substring> in <string> and <substring> not in <string>.