check if something is a string python code example

Example 1: python test if number in string

>>> def hasNumbers(inputString):
...     return any(char.isdigit() for char in inputString)
... 
>>> hasNumbers("I own 1 dog")
True
>>> hasNumbers("I own no dog")
False

Example 2: if type is string python

isinstance(s, str)

Example 3: python check if string in string

if "blah" not in somestring: 
    continue

Example 4: python check if string

type('hello world') == str
# output: True

type(10) == str
# output: False

Example 5: how to check a string in if statement python

if var in ('stringone', 'stringtwo'):
    dosomething()