Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | 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'>