To check if a string contains a specific substring in Python, you can use the in
keyword.
Here is an example:
main.py140 chars8 lines
This code will output "Substring found!" since the substring "World" is present in the string "Hello, World!".
You can also use the str.__contains__()
method to achieve the same result:
main.py151 chars8 lines
Both methods will give you the same output.
gistlibby LogSnag