Check if String Contains Substring in Python
In Python, you can use the ‘in’ operator to determine if a string contains a specific substring. For example:
string = "hello world"
substring = "hello"
if substring in string:
print("字符串包含特定子串")
else:
print("字符串不包含特定子串")
When running the above code, if the string contains the substring, it will output “String contains specific substring”; otherwise, it will output “String does not contain specific substring”.