summaryrefslogtreecommitdiffstats
path: root/Doc/lib
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-11-01 21:33:44 (GMT)
committerFred Drake <fdrake@acm.org>2002-11-01 21:33:44 (GMT)
commit9482d2591a89ebd5f5c79fa22dffe8b9db8a45d9 (patch)
tree3aa2998f29cb34fe72c9bbc3f5a6dc54db49c6bf /Doc/lib
parent57bc5fa60a25661237861b3d3c9941ca8f5dbfd7 (diff)
downloadcpython-9482d2591a89ebd5f5c79fa22dffe8b9db8a45d9.zip
cpython-9482d2591a89ebd5f5c79fa22dffe8b9db8a45d9.tar.gz
cpython-9482d2591a89ebd5f5c79fa22dffe8b9db8a45d9.tar.bz2
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.
Diffstat (limited to 'Doc/lib')
-rw-r--r--Doc/lib/libfuncs.tex15
1 files changed, 13 insertions, 2 deletions
diff --git a/Doc/lib/libfuncs.tex b/Doc/lib/libfuncs.tex
index 6463382..f6b01d1 100644
--- a/Doc/lib/libfuncs.tex
+++ b/Doc/lib/libfuncs.tex
@@ -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}