Search code examples
pythonstringsymbols

I'm looking for a function that is like 'str.isupper()' but with symbols?


I'm looking for a function that can do the exact same like str.isupper() but instead with symbols like:

symbols = '!@#$%^&*()-_+=`~;:\'[]{}|<>,./?'

foo = '@&(='

# and then a function somewhat like this

print(issymbol(foo)) # this should return true

Thanks!


Solution

  • For a single char, this is simply the in operator:

    print( char in symbols )
    

    For a string, use the all method:

    print (all (char in symbols for char in foo) )