Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

第 4 章 数据类型

目录

4.1. type 数据类型检测
4.2. String
4.2.1. String function
4.2.1.1. str.find()
4.2.1.2. str.find()
4.2.2. Convert str to bytes in python
4.2.3. String format
4.3. Array
4.3.1. split / join
4.4. Datetime
4.4.1. datetime
4.5. bytes 类型
4.5.1. BOM头
4.5.2. replace
4.5.3. pack/unpack

4.1. type 数据类型检测

http://docs.python.org/library/types.html

		
>>> type( [] ) == list
True
>>> type( {} ) == dict
True
>>> type( "" ) == str
True
>>> type( 0 ) == int
True
>>> class Test1 ( object ):
    pass
>>> class Test2 ( Test1 ):
    pass
>>> a = Test1()
>>> b = Test2()
>>> type( a ) == Test1
True
>>> type( b ) == Test2
True
>>> type( b ) == Test1
False
>>> isinstance( b, Test1 )
True
>>> isinstance( b, Test2 )
True
>>> isinstance( a, Test1 )
True
>>> isinstance( a, Test2 )
False
>>> isinstance( [], list )
True
>>> isinstance( {}, dict )
True
		
		
		
>>> a = []
>>> type(a)
<type 'list'>
>>> f = ()
>>> type(f)
<type 'tuple'>
		
		
comments powered by Disqus