Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine whether a substring is in a different string [duplicate]

Tags:

python

string

I have a sub-string:

substring = "please help me out" 

I have another string:

string = "please help me out so that I could solve this" 

How do I find if substring is a subset of string using Python?

like image 252
sunny Avatar asked Sep 09 '11 11:09

sunny


People also ask

How do you check if a substring is in another string?

You can use contains(), indexOf() and lastIndexOf() method to check if one String contains another String in Java or not. If a String contains another String then it's known as a substring. The indexOf() method accepts a String and returns the starting position of the string if it exists, otherwise, it will return -1.

How do you find whether a string is a substring of another string in Python?

Using the 'in' operator: The in operator is the easiest and pythonic way to check if a python string contains a substring. The in and not in are membership operators, they take in two arguments and evaluate if one is a member of the other. They return a boolean value.

How do you check if a string is substring of another string in C++?

Check if a string contains a sub-string in C++ This find() method returns the first location where the string is found. Here we are using this find() function multiple times to get all of the matches. If the item is found, this function returns the position. But if it is not found, it will return string::npos.


1 Answers

with in: substring in string:

>>> substring = "please help me out" >>> string = "please help me out so that I could solve this" >>> substring in string True 
like image 136
MarcoS Avatar answered Oct 22 '22 06:10

MarcoS