Verificando tipo da variável em Python (checking variable type)

Estava procurando um método, ou uma função, para Python equivalente aos is_int, is_float, is_string do PHP, até que método abaixo para a comparação, não sei se é o melhor método, em questão de performance, etc.. Segue abaixo a quem interessar.

publici@publici2-desktop:~/python/$ python
Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> type('teste') == str
True
>>> type(1) == int
True
>>> type(-1) == int
True
>>> type(1.5) == int
False
>>> type(1.5) == float
True
>>> type((1,2)) == tuple
True
>>> type([1,2]) == list
True

Até.


Outras postagens interessantes

Uma pessoa comentou

  1. linguagem bolada

Deixe o seu comentário

Você pode usar as seguintes tags no seu comentário: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

Para comentar um código, utilize por exemplo: <pre lang="php" line="2">echo 'Hello World';</pre>