Skip to content Skip to sidebar Skip to footer

Check Special Character In String?

i need to check existing of Character (*,&,$) in Given String using python command such as given below? Eg: stringexample='mystri$ng&*' check stringexample contains any spe

Solution 1:

>>> stringexample = 'mystri$ng&'
>>> '*' in stringexample
False
>>> '$' in stringexample
True
>>> '&' in stringexample
True
>>>

Solution 2:

if any(c in stringexample for c in '*$&'):
    ...

or

if not set('*&$').isdisjoint(stringexample):
    ...

Post a Comment for "Check Special Character In String?"