Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

checking if a string contains a substring python

fullstring = "StackAbuse"
substring = "tack"

if substring in fullstring:
    print("Found!")
else:
    print("Not found!")

# Output - Found!

fullstring = "StackAbuse"
substring_2 = "abuse"

if substring_2 in fullstring:
    print("Found!")
else:
    print("Not found!")

# Output - Not found! 
# (Remember this is case-sensitive)
Comment

how to check for a substring in python

def find_string(string,sub_string):
	return string.find(sub_string)
#.find() also accounts for multiple occurence of the substring in the given string
Comment

python check if string contains substring

string = "My favourite programming language is Python"
substring = "Python"

if substring in string:
    print("Python is my favorite language")
elif substring not in string:
    print("Python is not my favourite language")
Comment

PREVIOUS NEXT
Code Example
Python :: dataframe to dictionary using index as key 
Python :: python convert hex number to decimal 
Python :: django messages 
Python :: change dataframe to list 
Python :: if substring not in string python 
Python :: drop rows where specific column has null values 
Python :: how to dump a database using manage.py 
Python :: digit sum codechef 
Python :: Iterate through characters of a string in python 
Python :: print in python without using print or sys module 
Python :: distplot in python 
Python :: ord python 
Python :: downsample image opencv 
Python :: python datetime get weekday name 
Python :: print from within funciton with multiprocessing 
Python :: print A to z vy using loop in python 
Python :: list comprehension if elseif 
Python :: remove item list python 
Python :: pandas rename column by dictionary 
Python :: Access item in a list of lists 
Python :: save turtle programming python 
Python :: numpy divide with exception 
Python :: use the index of a dataframe for another dataframe 
Python :: python replace 
Python :: python program to find numbers divisible by another number 
Python :: python Change the second item 
Python :: how to use a function to find the average in python 
Python :: python how to see what pip packages are installed 
Python :: np.stack 
Python :: turtle keep window open 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =