0

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?

1 Answer 1

2

Use the in operator:

if "=" in a_str:

Demo:

>>> '=' in '!@#$%^'
False
>>> '=' in '=-0987'
True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.