Skip to content

Commit b46e004

Browse files
committed
📝 Simplify the exploration of Python
1 parent 39c59d3 commit b46e004

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

docs/editors.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Editors
22
=======
33

4+
5+
.. _interactive_shell:
6+
47
Interactive Shell
58
-----------------
69

docs/explore.rst

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Exploring Python
22
================
33

4-
Whether you use IDLE or the interactive shell, there are some useful functions
5-
to explore Python.
4+
Whether you use :ref:`idle` or the :ref:`interactive_shell`, there are some
5+
useful functions to explore Python.
66

77
.. _help:
88

@@ -40,26 +40,29 @@ variable name as a parameter, for example:
4040
| abs(self)
4141
...
4242
43-
``dir()``, ``globals()`` and ``locals()``
44-
-----------------------------------------
43+
For example, you will learn that ``x`` is of type ``float`` and has a function
44+
:func:`__add__` that you can use with dot notation:
4545

46-
:py:func:`dir` is another useful function that lists objects in a specific
47-
:doc:`namespace <oop/namespaces>`. If you use it without parameters, you can
48-
find out which methods and data are available locally. Alternatively, it can
49-
also list objects for a module or type.
46+
.. code-block:: pycon
47+
48+
>>> x.__add__(1)
49+
5.2
50+
51+
``dir()``
52+
---------
53+
54+
:py:func:`dir` is another useful function to find out which methods and data are
55+
available locally or for a specific object:
5056

5157
.. code-block:: pycon
5258
5359
>>> dir()
5460
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'x']
55-
>>> dir(x)
56-
['__abs__', '__add__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getformat__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__int__', '__le__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__pos__', '__pow__', '__radd__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmod__', '__rmul__', '__round__', '__rpow__', '__rsub__', '__rtruediv__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', 'as_integer_ratio', 'conjugate', 'fromhex', 'hex', 'imag', 'is_integer', 'real']
5761
58-
In contrast to :py:func:`dir`, both :py:func:`globals` and :py:func:`locals`
59-
display the values associated with the objects. Currently, both functions return
60-
the same thing:
62+
For example, we can use ``dir(__builtins__)`` to display a list of what is
63+
already available in the Python standard library:
6164

6265
.. code-block:: pycon
6366
64-
>>> globals()
65-
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'x': 4.2}
67+
>>> dir(__builtins__)
68+
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BaseExceptionGroup', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EncodingWarning', 'EnvironmentError', 'Exception', 'ExceptionGroup', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'PythonFinalizationError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '_', '_IncompleteInputError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'aiter', 'all', 'anext', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']

docs/oop/private.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ it can access and output ``__y``:
4747
>>> m.print_y()
4848
2
4949
50-
.. note::
50+
.. warning::
5151

5252
The mechanism used to ensure privacy falsifies the name of private variables
5353
and private methods when the code is compiled into bytecode. Specifically,

0 commit comments

Comments
 (0)