Home > database >  How to check if some datatype is string or list in python?
How to check if some datatype is string or list in python?

Time:12-04

I'm trying to add a check here that if the receiver is just a string. then convert that into list else just pass.

  if type(receiver) == str:
        receiver=[receiver]

error: TypeError: 'str' object is not callable

CodePudding user response:

You can check the type of an instance with the following.

if isinstance(receiver, str):
    # do something if it is a string

If you just need to check rather it is not a string:

if not isinstance(receiver, str):
    # do something if it is not a string

Look at this tutorial to learn more about the function.

CodePudding user response:

a = '123'
print(str(a))
print(type(a))
  • Related