mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
Update example for the type() function to use the currently accepted
preference of using "is" instead of "==" to compare types, use built-in names where available, and point to the isinstance() function. Closes SF bug #632196.
This commit is contained in:
parent
57bc5fa60a
commit
9482d2591a
1 changed files with 13 additions and 2 deletions
|
|
@ -836,13 +836,24 @@ def my_import(name):
|
|||
Return the type of an \var{object}. The return value is a
|
||||
type\obindex{type} object. The standard module
|
||||
\module{types}\refstmodindex{types} defines names for all built-in
|
||||
types.
|
||||
types that don't already have built-in names.
|
||||
For instance:
|
||||
|
||||
\begin{verbatim}
|
||||
>>> import types
|
||||
>>> if type(x) == types.StringType: print "It's a string"
|
||||
>>> x = 'abc'
|
||||
>>> if type(x) is str: print "It's a string"
|
||||
...
|
||||
It's a string
|
||||
>>> def f(): pass
|
||||
...
|
||||
>>> if type(f) is types.FunctionType: print "It's a function"
|
||||
...
|
||||
It's a function
|
||||
\end{verbatim}
|
||||
|
||||
The \function{isinstance()} built-in function is recommended for
|
||||
testing the type of an object.
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{unichr}{i}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue