Jake Jackson
Jake Jackson

Reputation: 1235

How to check *args are all strings

What is an efficient way to check that all the arguments passed into a function are instances of str?

def foo(*args):
    assert isinstance(*args, str)
    ...

Would it be to do it in a for loop or is there a better way?

Upvotes: 1

Views: 166

Answers (1)

Alex
Alex

Reputation: 7045

Here you want to be using all()

def foo(*args):
    assert all(isinstance(a, str) for a in args)
    # ...

Upvotes: 1

Related Questions