Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6c45dc12
Commit
6c45dc12
authored
Mar 06, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add isinstance/issubclass to tutorial.
parent
26bab5f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
Doc/tutorial/classes.rst
Doc/tutorial/classes.rst
+16
-0
No files found.
Doc/tutorial/classes.rst
View file @
6c45dc12
...
...
@@ -420,6 +420,9 @@ classes defined in it. Usually, the class containing the method is itself
defined in this global scope, and in the next section we'll find some good
reasons why a method would want to reference its own class!
Each value is an object, and therefore has a *class* (also called its *type*).
It is stored as ``object.__class__``.
.. _tut-inheritance:
...
...
@@ -469,6 +472,19 @@ arguments)``. This is occasionally useful to clients as well. (Note that this
only works if the base class is defined or imported directly in the global
scope.)
Python has two builtin functions that work with inheritance:
* Use :func:`isinstance` to check an object's type: ``isinstance(obj, int)``
will be ``True`` only if ``obj.__class__`` is :class:`int` or some class
derived from :class:`int`.
* Use :func:`issubclass` to check class inheritance: ``issubclass(bool, int)``
is ``True`` since :class:`bool` is a subclass of :class:`int`. However,
``issubclass(unicode, str)`` is ``False`` since :class:`unicode` is not a
subclass of :class:`str` (they only share a common ancestor,
:class:`basestring`).
.. _tut-multiple:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment