啟動Python interpreter之後,就已經可以使用一些東西,這些東西稱為Python的內建(built-in)物件,是Python程式語言本身的一部分(即Python的核心)。我們可以使用「__builtin__」模組存取這些內建物件,使用len(dir(__builtin__))或len(__builtins__)指令可以發現總共有144個,這些內建物件可以分成下列4類:
- 內建常數,共11個
- Python程式語言本身內建,共6個
- False
- True
- None
- NotImplemented
- Ellipsis
- __debug__
- 因Python自動匯入site模組,額外加入常數至內建名稱空間之中,共5個
- quit
- exit
- copyritht
- license
- credits
- 內建型別,共28個
- basestring
- bool
- buffer
- bytearray
- bytes (bytes型別是Python 3.0才正式新增,2.x版的bytes等於str型別)
- classmethod
- complex
- dict
- enumerate
- file
- float
- frozenset
- int
- list
- long
- memoryview
- object
- property
- reversed
- set
- slice
- staticmethod
- str
- super
- tuple
- type
- unicode
- xrange
- 內建函式,共53個
- __import__
- abs
- all
- any
- apply
- bin
- callable
- chr
- cmp
- coerce
- compile
- delattr
- dir
- divmod
- eval
- execfile
- filter
- format
- getattr
- globals
- hasattr
- hash
- help:因Python自動匯入site模組,額外加入至內建函式中
- hex
- id
- input
- intern
- isinstance
- issubclass
- iter
- len
- locals
- map
- max
- min
- next
- oct
- open
- ord
- pow
- range
- raw_input
- reduce
- reload
- repr
- round
- setattr
- sorted
- sum
- unichr
- vars
- zip
- 內建例外,共48個
- ArithmeticError
- AssertionError
- AttributeError
- BaseException
- BufferError
- BytesWarning
- DeprecationWarning
- EOFError
- EnvironmentError
- Exception
- FloatingPointError
- FutureWarning
- GeneratorExit
- IOError
- ImportError
- ImportWarning
- IndentationError
- IndexError
- KeyError
- KeyboardInterrupt
- LookupError
- MemoryError
- NameError
- NotImplementedError
- OSError
- OverflowError
- PendingDeprecationWarning
- ReferenceError
- RuntimeError
- RuntimeWarning
- StandardError
- StopIteration
- SyntaxError
- SyntaxWarning
- SystemError
- SystemExit
- TabError
- TypeError
- UnboundLocalError
- UnicodeDecodeError
- UnicodeEncodeError
- UnicodeError
- UnicodeTranslateError
- UnicodeWarning
- UserWarning
- ValueError
- Warning
- ZeroDivisionError
- _:上一次最新輸出的結果(last printed expression)
- __doc__:文件字串
- __name__:名稱
- __package__:套件
###
沒有留言:
張貼留言