In Python, membership testing for strings can be done using the in keyword. This allows you to check if a substring exists within a string. Here’s an example:
# Example string
text = "Hello, welcome to Python programming!"
# Membership testing
substring = "Python"
if substring in text:
print(f"'{substring}' is found in the text.")
else:
print(f"'{substring}' is not found in the text.")
In this example, the code checks if the substring "Python" is present in the text string and prints the appropriate message based on the result.
