Knowing the type of return of a given

Asked

Viewed 49 times

0

I have a problem with the return type of a data in python. I was first trying :

    >>> type(record[0][keys[2]])
<class 'Bio.Entrez.Parser.StringElement'>

I tried to check by if

>>> type(record[0][keys[2]])is list
>>> type(record[0][keys[2]])is string
>>> type(record[0][keys[2]])is array

all return Falso

I’ve also compared it with the whole guy 'Bio.Entrez.Parser.StringElement' and also of Falso. Then I changed the abortion I’ll see if there is a string type word I want in the Reset <class 'Bio.Entrez.Parser.StringElement'> of function type to make this comparison I have to pick up the string inside < > for me to make that comparison? How to do this ?

2 answers

0

Expressly do so:

type(<Objecto>) is <Tipo>

For example:

type("Eu sou uma String!") is str # => True

0

Use the 'isinstance'. example:

if isinstance(<Object>, <Class>):
    faz qualquer coisa
else:
    faz outra coisa

Browser other questions tagged

You are not signed in. Login or sign up in order to post.