python中的类型判定

python中的类型判定有如下几种方法:
(1)>>>print type(1)==int
True
(2)isinstance(1,(int,str))
True
注意,此处第二个参数可以是个tuple,只要第一个参数是其中任何一个类型时,就返回True
(3)import types
>>> int
<type ‘int’>
>>> IntType
<type ‘int’>
>>> print int is IntType
True
可知,IntType和int是同一类型对象,具有同一object id。

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Related posts:

  1. Built-in Functions

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu