user3014764
user3014764

Reputation: 9

Finding a specific character in a string

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

Answers (1)

Ashwini Chaudhary
Ashwini Chaudhary

Reputation: 251136

Use the in operator:

if "=" in a_str:

Demo:

>>> '=' in '!@#$%^'
False
>>> '=' in '=-0987'
True

Upvotes: 2

Related Questions