KnowledgeBoat Logo

Computer Science

Explain the membership operators in String.

Python String Manipulation

3 Likes

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>.

Answered By

3 Likes


Related Questions