Python - String Manipulation (Part-2)
Question and Answers
CBSE Class 11 - Informatics Practices
Q1: What are membership operators for strings?
Answer: Two membership operators are:
in Returns True if a substring exists in the given string otherwise returns false.
e.g. "xy" in "xyz" #returns True
"ab" in "xyz" #returns False
not in Returns True is a substring does not exist in the given string;
e.g. "ab" not in "xyz" #returns True
"xy" not in "xyz" #returns False
Q2: What is the output of the following?
str1 = "Hello World!"
str2 = "he"
str3 = "He"
str2 in str1
str3 in str1