Reputation: 9
I'm trying to create a function that takes a string input, and checks if it has "=" or ">" inside it, then returns a list after applying the built in string method "strip" to it on "=" or ">". In order to do this, I am writing an if and elif statement.
def split_list_math(a_str):
if(contains("=") == True):
a_str2 = a_str.split("=")
elif(contains(">") == True):
a_str2 = a_str.split(">")
return a_str2
What can I replace "contain" with in my code in order to make this function work?
Upvotes: 0
Views: 75
Reputation: 251136
Use the in
operator:
if "=" in a_str:
Demo:
>>> '=' in '!@#$%^'
False
>>> '=' in '=-0987'
True
Upvotes: 2