chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
29558154-54a9-4f81-9398-deddce01237f | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,764 | supabase-export-v2 | 9757dc76a0764a6b | than when it is read from a ``.py`` file; the only thing that's faster about ``.pyc`` files is the speed with which they are loaded.
* The module :mod:`compileall` can create .pyc files for all modules in a
directory. | trusted_official_docs | CPython Docs | than when it is read from a ``.py`` file; the only thing that's faster about ``.pyc`` files is the speed with which they are loaded.
* The module :mod:`compileall` can create .pyc files for all modules in a
directory. | than when it is read from a ``.py`` file; the only thing that's faster about ``.pyc`` files is the speed with which they are loaded.
* The module :mod:`compileall` can create .pyc files for all modules in a
directory. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2fa2ac90-9c89-413a-9f95-98323a938794 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,822 | supabase-export-v2 | e72f17416b924077 | Intra-package References ------------------------
When packages are structured into subpackages (as with the :mod:`!sound` package
in the example), you can use absolute imports to refer to submodules of siblings
packages. For example, if the module :mod:`!sound.filters.vocoder` needs to use
the :mod:`!echo` module in t... | trusted_official_docs | CPython Docs | Intra-package References ------------------------
When packages are structured into subpackages (as with the :mod:`!sound` package
in the example), you can use absolute imports to refer to submodules of siblings
packages. For example, if the module :mod:`!sound.filters.vocoder` needs to use
the :mod:`!echo` module in t... | Intra-package References ------------------------
When packages are structured into subpackages (as with the :mod:`!sound` package
in the example), you can use absolute imports to refer to submodules of siblings
packages. For example, if the module :mod:`!sound.filters.vocoder` needs to use
the :mod:`!echo` module in t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
36700fc6-3ff6-4966-b9f2-e859d4307c66 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,824 | supabase-export-v2 | 29cdb5511574196b | imports use leading dots to indicate the current and parent packages involved in the relative import. From the :mod:`!surround` module for example, you might use::
from . import echo
from .. import formats
from ..filters import equalizer | trusted_official_docs | CPython Docs | imports use leading dots to indicate the current and parent packages involved in the relative import. From the :mod:`!surround` module for example, you might use::
from . import echo
from .. import formats
from ..filters import equalizer | imports use leading dots to indicate the current and parent packages involved in the relative import. From the :mod:`!surround` module for example, you might use::
from . import echo
from .. import formats
from ..filters import equalizer | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3734317e-eb33-4554-8543-5a39fe73a79c | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,819 | supabase-export-v2 | acc5eb7af6cc003e | modules are designed to export only names that follow certain patterns when you use ``import *``, it is still considered bad practice in production code.
Remember, there is nothing wrong with using ``from package import
specific_submodule``! In fact, this is the recommended notation unless the
importing module needs to... | trusted_official_docs | CPython Docs | modules are designed to export only names that follow certain patterns when you use ``import *``, it is still considered bad practice in production code.
Remember, there is nothing wrong with using ``from package import
specific_submodule``! In fact, this is the recommended notation unless the
importing module needs to... | modules are designed to export only names that follow certain patterns when you use ``import *``, it is still considered bad practice in production code.
Remember, there is nothing wrong with using ``from package import
specific_submodule``! In fact, this is the recommended notation unless the
importing module needs to... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
37a8d028-cd1b-4e38-978a-81d184b2be3c | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,709 | supabase-export-v2 | 692fd2e64fc48768 | Fibonacci series up to n.""" result = [] a, b = 0, 1 while a < n: result.append(a) a, b = b, a+b return result
Now enter the Python interpreter and import this module with the following
command:: | trusted_official_docs | CPython Docs | Fibonacci series up to n.""" result = [] a, b = 0, 1 while a < n: result.append(a) a, b = b, a+b return result
Now enter the Python interpreter and import this module with the following
command:: | Fibonacci series up to n.""" result = [] a, b = 0, 1 while a < n: result.append(a) a, b = b, a+b return result
Now enter the Python interpreter and import this module with the following
command:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3ab83b9c-274d-4a0b-8a89-5a349df54bee | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,718 | supabase-export-v2 | dda86463ee63addd | the *first* time the module name is encountered in an import statement. [#]_ (They are also run if the file is executed as a script.)
Each module has its own private namespace, which is used as the global namespace
by all functions defined in the module. Thus, the author of a module can
use global variables in the modu... | trusted_official_docs | CPython Docs | the *first* time the module name is encountered in an import statement. [#]_ (They are also run if the file is executed as a script.)
Each module has its own private namespace, which is used as the global namespace
by all functions defined in the module. Thus, the author of a module can
use global variables in the modu... | the *first* time the module name is encountered in an import statement. [#]_ (They are also run if the file is executed as a script.)
Each module has its own private namespace, which is used as the global namespace
by all functions defined in the module. Thus, the author of a module can
use global variables in the modu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3f094305-23dd-47ed-9082-8603b97f8f9d | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,780 | supabase-export-v2 | 287b459f1cd5250d | >>> a = [1, 2, 3, 4, 5] >>> import fibo >>> fib = fibo.fib >>> dir() ['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']
Note that it lists all types of names: variables, modules, functions, etc. | trusted_official_docs | CPython Docs | >>> a = [1, 2, 3, 4, 5] >>> import fibo >>> fib = fibo.fib >>> dir() ['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']
Note that it lists all types of names: variables, modules, functions, etc. | >>> a = [1, 2, 3, 4, 5] >>> import fibo >>> fib = fibo.fib >>> dir() ['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']
Note that it lists all types of names: variables, modules, functions, etc. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
48f226df-d0a7-4359-95c8-1065b767e56d | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,723 | supabase-export-v2 | 1949edc334b38f05 | This does not introduce the module name from which the imports are taken in the local namespace (so in the example, ``fibo`` is not defined).
There is even a variant to import all names that a module defines:: | trusted_official_docs | CPython Docs | This does not introduce the module name from which the imports are taken in the local namespace (so in the example, ``fibo`` is not defined).
There is even a variant to import all names that a module defines:: | This does not introduce the module name from which the imports are taken in the local namespace (so in the example, ``fibo`` is not defined).
There is even a variant to import all names that a module defines:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4cb1adc0-35d7-4150-bc7b-ed475f8e1e4f | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,771 | supabase-export-v2 | 09f5ec6c242a1fb2 | >>> import sys >>> sys.ps1 '>>> ' >>> sys.ps2 '... ' >>> sys.ps1 = 'C> ' C> print('Yuck!') Yuck! C>
These two variables are only defined if the interpreter is in interactive mode. | trusted_official_docs | CPython Docs | >>> import sys >>> sys.ps1 '>>> ' >>> sys.ps2 '... ' >>> sys.ps1 = 'C> ' C> print('Yuck!') Yuck! C>
These two variables are only defined if the interpreter is in interactive mode. | >>> import sys >>> sys.ps1 '>>> ' >>> sys.ps2 '... ' >>> sys.ps1 = 'C> ' C> print('Yuck!') Yuck! C>
These two variables are only defined if the interpreter is in interactive mode. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4ed4f289-c88c-4e33-8d10-c51d6cde0012 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,763 | supabase-export-v2 | e61fc861be31e6f2 | option if you know what you're doing. "Optimized" modules have an ``opt-`` tag and are usually smaller. Future releases may change the effects of optimization.
* A program doesn't run any faster when it is read from a ``.pyc``
file than when it is read from a ``.py`` file; the only thing that's faster
about ``.pyc`` ... | trusted_official_docs | CPython Docs | option if you know what you're doing. "Optimized" modules have an ``opt-`` tag and are usually smaller. Future releases may change the effects of optimization.
* A program doesn't run any faster when it is read from a ``.pyc``
file than when it is read from a ``.py`` file; the only thing that's faster
about ``.pyc`` ... | option if you know what you're doing. "Optimized" modules have an ``opt-`` tag and are usually smaller. Future releases may change the effects of optimization.
* A program doesn't run any faster when it is read from a ``.pyc``
file than when it is read from a ``.py`` file; the only thing that's faster
about ``.pyc`` ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
500b2fcd-78b3-4610-acc4-fde56e31f967 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,760 | supabase-export-v2 | c7add3818914a12c | recompiled. This is a completely automatic process. Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.
Python does not check the cache in two circumstances. First, it always
recompiles and does not store the result for the module that's loa... | trusted_official_docs | CPython Docs | recompiled. This is a completely automatic process. Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.
Python does not check the cache in two circumstances. First, it always
recompiles and does not store the result for the module that's loa... | recompiled. This is a completely automatic process. Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.
Python does not check the cache in two circumstances. First, it always
recompiles and does not store the result for the module that's loa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
51011735-7c1c-4599-b36d-912d5d840cff | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,732 | supabase-export-v2 | bbc077aaa45ebfac | It can also be used when utilising :keyword:`from` with similar effects::
>>> from fibo import fib as fibonacci
>>> fibonacci(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | trusted_official_docs | CPython Docs | It can also be used when utilising :keyword:`from` with similar effects::
>>> from fibo import fib as fibonacci
>>> fibonacci(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | It can also be used when utilising :keyword:`from` with similar effects::
>>> from fibo import fib as fibonacci
>>> fibonacci(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
53a8f2bb-dcdb-4ed4-bc5c-c07a0d39bfd1 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,825 | supabase-export-v2 | 9cb9359c4089f88c | from . import echo from .. import formats from ..filters import equalizer
Note that relative imports are based on the name of the current module's package. Since the main module does not have a package, modules intended for use
as the main module of a Python application must always use absolute imports. | trusted_official_docs | CPython Docs | from . import echo from .. import formats from ..filters import equalizer
Note that relative imports are based on the name of the current module's package. Since the main module does not have a package, modules intended for use
as the main module of a Python application must always use absolute imports. | from . import echo from .. import formats from ..filters import equalizer
Note that relative imports are based on the name of the current module's package. Since the main module does not have a package, modules intended for use
as the main module of a Python application must always use absolute imports. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
54ba11c4-358a-48bf-ac4f-da4e46a96dca | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,712 | supabase-export-v2 | 02960baab7f0f496 | the current :term:`namespace` (see :ref:`tut-scopes` for more details); it only adds the module name ``fibo`` there. Using the module name you can access the functions::
>>> fibo.fib(1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
>>> fibo.fib2(100)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>>> fibo.__name__... | trusted_official_docs | CPython Docs | the current :term:`namespace` (see :ref:`tut-scopes` for more details); it only adds the module name ``fibo`` there. Using the module name you can access the functions::
>>> fibo.fib(1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
>>> fibo.fib2(100)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>>> fibo.__name__... | the current :term:`namespace` (see :ref:`tut-scopes` for more details); it only adds the module name ``fibo`` there. Using the module name you can access the functions::
>>> fibo.fib(1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
>>> fibo.fib2(100)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>>> fibo.__name__... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
55777969-0a51-4232-a522-8a4546880980 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,818 | supabase-export-v2 | e55e3bfc2cde5040 | in the current namespace because they are defined in the :mod:`!sound.effects` package when the ``from...import`` statement is executed. (This also works when ``__all__`` is defined.)
Although certain modules are designed to export only names that follow certain
patterns when you use ``import *``, it is still considere... | trusted_official_docs | CPython Docs | in the current namespace because they are defined in the :mod:`!sound.effects` package when the ``from...import`` statement is executed. (This also works when ``__all__`` is defined.)
Although certain modules are designed to export only names that follow certain
patterns when you use ``import *``, it is still considere... | in the current namespace because they are defined in the :mod:`!sound.effects` package when the ``from...import`` statement is executed. (This also works when ``__all__`` is defined.)
Although certain modules are designed to export only names that follow certain
patterns when you use ``import *``, it is still considere... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
598ea5d5-d468-4c18-aa24-40b58d1fe1cf | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,730 | supabase-export-v2 | 2131ab0b664e1b74 | >>> import fibo as fib >>> fib.fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This is effectively importing the module in the same way that ``import fibo``
will do, with the only difference of it being available as ``fib``. | trusted_official_docs | CPython Docs | >>> import fibo as fib >>> fib.fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This is effectively importing the module in the same way that ``import fibo``
will do, with the only difference of it being available as ``fib``. | >>> import fibo as fib >>> fib.fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This is effectively importing the module in the same way that ``import fibo``
will do, with the only difference of it being available as ``fib``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
59ea478a-1f11-4dda-ba6f-5c8d9dee48c8 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,828 | supabase-export-v2 | f08e0072af6e183e | the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.
While this feature is not often needed, it can be used to extend the set of
modules found in a package. | trusted_official_docs | CPython Docs | the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.
While this feature is not often needed, it can be used to extend the set of
modules found in a package. | the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.
While this feature is not often needed, it can be used to extend the set of
modules found in a package. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5ab61a4d-4d60-4dda-9b6f-c85808979bfd | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,758 | supabase-export-v2 | 95b09acdf7e3d370 | "Compiled" Python files -----------------------
To speed up loading modules, Python caches the compiled version of each module
in the ``__pycache__`` directory under the name :file:`module.{version}.pyc`,
where the version encodes the format of the compiled file; it generally contains
the Python version number. For exa... | trusted_official_docs | CPython Docs | "Compiled" Python files -----------------------
To speed up loading modules, Python caches the compiled version of each module
in the ``__pycache__`` directory under the name :file:`module.{version}.pyc`,
where the version encodes the format of the compiled file; it generally contains
the Python version number. For exa... | "Compiled" Python files -----------------------
To speed up loading modules, Python caches the compiled version of each module
in the ``__pycache__`` directory under the name :file:`module.{version}.pyc`,
where the version encodes the format of the compiled file; it generally contains
the Python version number. For exa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5b21fe77-13b5-434f-979d-c1cad3896255 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,722 | supabase-export-v2 | 11b7d8e92b728885 | >>> from fibo import fib, fib2 >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This does not introduce the module name from which the imports are taken in the
local namespace (so in the example, ``fibo`` is not defined). | trusted_official_docs | CPython Docs | >>> from fibo import fib, fib2 >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This does not introduce the module name from which the imports are taken in the
local namespace (so in the example, ``fibo`` is not defined). | >>> from fibo import fib, fib2 >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This does not introduce the module name from which the imports are taken in the
local namespace (so in the example, ``fibo`` is not defined). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5bc92652-70fe-44b5-a152-c4f2fa73dade | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,816 | supabase-export-v2 | 3953c9ae0939fe17 | (and submodules explicitly loaded) by :file:`__init__.py`. It also includes any submodules of the package that were explicitly loaded by previous :keyword:`import` statements. Consider this code::
import sound.effects.echo
import sound.effects.surround
from sound.effects import * | trusted_official_docs | CPython Docs | (and submodules explicitly loaded) by :file:`__init__.py`. It also includes any submodules of the package that were explicitly loaded by previous :keyword:`import` statements. Consider this code::
import sound.effects.echo
import sound.effects.surround
from sound.effects import * | (and submodules explicitly loaded) by :file:`__init__.py`. It also includes any submodules of the package that were explicitly loaded by previous :keyword:`import` statements. Consider this code::
import sound.effects.echo
import sound.effects.surround
from sound.effects import * | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5d056242-c26c-4ccf-9e24-f90c21f767db | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,725 | supabase-export-v2 | ee755764755892e0 | >>> from fibo import * >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This imports all names except those beginning with an underscore (``_``). In most cases Python programmers do not use this facility since it introduces
an unknown set of names into the interpreter, possibly hiding some things
you have already ... | trusted_official_docs | CPython Docs | >>> from fibo import * >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This imports all names except those beginning with an underscore (``_``). In most cases Python programmers do not use this facility since it introduces
an unknown set of names into the interpreter, possibly hiding some things
you have already ... | >>> from fibo import * >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
This imports all names except those beginning with an underscore (``_``). In most cases Python programmers do not use this facility since it introduces
an unknown set of names into the interpreter, possibly hiding some things
you have already ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5ea14232-f775-447a-b4ef-3cc25d59e242 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,789 | supabase-export-v2 | 59388c65b349cba5 | wavwrite.py aiffread.py aiffwrite.py auread.py auwrite.py ... effects/ Subpackage for sound effects __init__.py echo.py surround.py reverse.py ... filters/ Subpackage for filters __init__.py equalizer.py vocoder.py karaoke.py ...
When importing the package, Python searches through the directories on
``sys.path`` lookin... | trusted_official_docs | CPython Docs | wavwrite.py aiffread.py aiffwrite.py auread.py auwrite.py ... effects/ Subpackage for sound effects __init__.py echo.py surround.py reverse.py ... filters/ Subpackage for filters __init__.py equalizer.py vocoder.py karaoke.py ...
When importing the package, Python searches through the directories on
``sys.path`` lookin... | wavwrite.py aiffread.py aiffwrite.py auread.py auwrite.py ... effects/ Subpackage for sound effects __init__.py echo.py surround.py reverse.py ... filters/ Subpackage for filters __init__.py equalizer.py vocoder.py karaoke.py ...
When importing the package, Python searches through the directories on
``sys.path`` lookin... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5f9d5d6a-ba37-4a63-bf96-3650c5ad0580 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,812 | supabase-export-v2 | 1b1fd869f4bfaa3d | This would mean that ``from sound.effects import *`` would import the three named submodules of the :mod:`!sound.effects` package.
Be aware that submodules might become shadowed by locally defined names. For
example, if you added a ``reverse`` function to the
:file:`sound/effects/__init__.py` file, the ``from sound.eff... | trusted_official_docs | CPython Docs | This would mean that ``from sound.effects import *`` would import the three named submodules of the :mod:`!sound.effects` package.
Be aware that submodules might become shadowed by locally defined names. For
example, if you added a ``reverse`` function to the
:file:`sound/effects/__init__.py` file, the ``from sound.eff... | This would mean that ``from sound.effects import *`` would import the three named submodules of the :mod:`!sound.effects` package.
Be aware that submodules might become shadowed by locally defined names. For
example, if you added a ``reverse`` function to the
:file:`sound/effects/__init__.py` file, the ``from sound.eff... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
64c77c29-2513-4386-8766-d4a5da9193ff | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,826 | supabase-export-v2 | 200925a5c31ba400 | the main module does not have a package, modules intended for use as the main module of a Python application must always use absolute imports.
Packages in Multiple Directories
-------------------------------- | trusted_official_docs | CPython Docs | the main module does not have a package, modules intended for use as the main module of a Python application must always use absolute imports.
Packages in Multiple Directories
-------------------------------- | the main module does not have a package, modules intended for use as the main module of a Python application must always use absolute imports.
Packages in Multiple Directories
-------------------------------- | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
66617994-5a03-42ab-9abd-724776fb1b37 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,808 | supabase-export-v2 | 6f2478c5f62a171c | .. index:: single: __all__
Now what happens when the user writes ``from sound.effects import *``? Ideally,
one would hope that this somehow goes out to the filesystem, finds which
submodules are present in the package, and imports them all. This could take a
long time and importing sub-modules might have unwanted side-... | trusted_official_docs | CPython Docs | .. index:: single: __all__
Now what happens when the user writes ``from sound.effects import *``? Ideally,
one would hope that this somehow goes out to the filesystem, finds which
submodules are present in the package, and imports them all. This could take a
long time and importing sub-modules might have unwanted side-... | .. index:: single: __all__
Now what happens when the user writes ``from sound.effects import *``? Ideally,
one would hope that this somehow goes out to the filesystem, finds which
submodules are present in the package, and imports them all. This could take a
long time and importing sub-modules might have unwanted side-... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
67d17b79-9d88-4220-a9df-866446765660 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,823 | supabase-export-v2 | d76dc42c906bf2d2 | siblings packages. For example, if the module :mod:`!sound.filters.vocoder` needs to use the :mod:`!echo` module in the :mod:`!sound.effects` package, it can use ``from sound.effects import echo``.
You can also write relative imports, with the ``from module import name`` form
of import statement. These imports use lead... | trusted_official_docs | CPython Docs | siblings packages. For example, if the module :mod:`!sound.filters.vocoder` needs to use the :mod:`!echo` module in the :mod:`!sound.effects` package, it can use ``from sound.effects import echo``.
You can also write relative imports, with the ``from module import name`` form
of import statement. These imports use lead... | siblings packages. For example, if the module :mod:`!sound.filters.vocoder` needs to use the :mod:`!echo` module in the :mod:`!sound.effects` package, it can use ``from sound.effects import echo``.
You can also write relative imports, with the ``from module import name`` form
of import statement. These imports use lead... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
69947df3-67fa-4598-a57e-17b015d02307 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,803 | supabase-export-v2 | 9c39a89508859e01 | echofilter(input, output, delay=0.7, atten=4)
Note that when using ``from package import item``, the item can be either a
submodule (or subpackage) of the package, or some other name defined in the
package, like a function, class or variable. The ``import`` statement first
tests whether the item is defined in the packa... | trusted_official_docs | CPython Docs | echofilter(input, output, delay=0.7, atten=4)
Note that when using ``from package import item``, the item can be either a
submodule (or subpackage) of the package, or some other name defined in the
package, like a function, class or variable. The ``import`` statement first
tests whether the item is defined in the packa... | echofilter(input, output, delay=0.7, atten=4)
Note that when using ``from package import item``, the item can be either a
submodule (or subpackage) of the package, or some other name defined in the
package, like a function, class or variable. The ``import`` statement first
tests whether the item is defined in the packa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6e2f8847-4f89-4023-9539-f7b149224929 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,726 | supabase-export-v2 | f667983a1490a192 | programmers do not use this facility since it introduces an unknown set of names into the interpreter, possibly hiding some things you have already defined.
Note that in general the practice of importing ``*`` from a module or package is
frowned upon, since it often causes poorly readable code. However, it is okay to
u... | trusted_official_docs | CPython Docs | programmers do not use this facility since it introduces an unknown set of names into the interpreter, possibly hiding some things you have already defined.
Note that in general the practice of importing ``*`` from a module or package is
frowned upon, since it often causes poorly readable code. However, it is okay to
u... | programmers do not use this facility since it introduces an unknown set of names into the interpreter, possibly hiding some things you have already defined.
Note that in general the practice of importing ``*`` from a module or package is
frowned upon, since it often causes poorly readable code. However, it is okay to
u... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
715cd31d-db8b-4863-ad23-dbaf9e40362d | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,731 | supabase-export-v2 | ac1948b18c162717 | This is effectively importing the module in the same way that ``import fibo`` will do, with the only difference of it being available as ``fib``.
It can also be used when utilising :keyword:`from` with similar effects:: | trusted_official_docs | CPython Docs | This is effectively importing the module in the same way that ``import fibo`` will do, with the only difference of it being available as ``fib``.
It can also be used when utilising :keyword:`from` with similar effects:: | This is effectively importing the module in the same way that ``import fibo`` will do, with the only difference of it being available as ``fib``.
It can also be used when utilising :keyword:`from` with similar effects:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
72b4c239-5599-4387-bcd5-be1b585ea008 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,817 | supabase-export-v2 | 748d37e23b45ad33 | import sound.effects.echo import sound.effects.surround from sound.effects import *
In this example, the :mod:`!echo` and :mod:`!surround` modules are imported in the
current namespace because they are defined in the :mod:`!sound.effects` package
when the ``from...import`` statement is executed. (This also works when
`... | trusted_official_docs | CPython Docs | import sound.effects.echo import sound.effects.surround from sound.effects import *
In this example, the :mod:`!echo` and :mod:`!surround` modules are imported in the
current namespace because they are defined in the :mod:`!sound.effects` package
when the ``from...import`` statement is executed. (This also works when
`... | import sound.effects.echo import sound.effects.surround from sound.effects import *
In this example, the :mod:`!echo` and :mod:`!surround` modules are imported in the
current namespace because they are defined in the :mod:`!sound.effects` package
when the ``from...import`` statement is executed. (This also works when
`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7343901e-4f67-4544-bd86-ab16007ddeab | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,741 | supabase-export-v2 | 776673dbd707ca43 | if __name__ == "__main__": import sys fib(int(sys.argv[1]))
you can make the file usable as a script as well as an importable module,
because the code that parses the command line only runs if the module is
executed as the "main" file: | trusted_official_docs | CPython Docs | if __name__ == "__main__": import sys fib(int(sys.argv[1]))
you can make the file usable as a script as well as an importable module,
because the code that parses the command line only runs if the module is
executed as the "main" file: | if __name__ == "__main__": import sys fib(int(sys.argv[1]))
you can make the file usable as a script as well as an importable module,
because the code that parses the command line only runs if the module is
executed as the "main" file: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
736edbca-2c9d-4fb2-92d9-846468291771 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,830 | supabase-export-v2 | a4ba4b6af2d611be | .. rubric:: Footnotes
.. [#] In fact function definitions are also 'statements' that are 'executed'; the
execution of a module-level function definition adds the function name to
the module's global namespace. | trusted_official_docs | CPython Docs | .. rubric:: Footnotes
.. [#] In fact function definitions are also 'statements' that are 'executed'; the
execution of a module-level function definition adds the function name to
the module's global namespace. | .. rubric:: Footnotes
.. [#] In fact function definitions are also 'statements' that are 'executed'; the
execution of a module-level function definition adds the function name to
the module's global namespace. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
73e0fc0f-c912-429e-9885-d250c078ac43 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,713 | supabase-export-v2 | adbf86fb30d33059 | 34 55 89 144 233 377 610 987 >>> fibo.fib2(100) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> fibo.__name__ 'fibo'
If you intend to use a function often you can assign it to a local name:: | trusted_official_docs | CPython Docs | 34 55 89 144 233 377 610 987 >>> fibo.fib2(100) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> fibo.__name__ 'fibo'
If you intend to use a function often you can assign it to a local name:: | 34 55 89 144 233 377 610 987 >>> fibo.fib2(100) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> fibo.__name__ 'fibo'
If you intend to use a function often you can assign it to a local name:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
75dc06b7-1b1a-45a7-ba0f-4ee898a6a857 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,813 | supabase-export-v2 | c9a7a511193779be | *`` would only import the two submodules ``echo`` and ``surround``, but *not* the ``reverse`` submodule, because it is shadowed by the locally defined ``reverse`` function::
__all__ = [
"echo", # refers to the 'echo.py' file
"surround", # refers to the 'surround.py' file
"reverse", # !!! refers to the 'reverse' func... | trusted_official_docs | CPython Docs | *`` would only import the two submodules ``echo`` and ``surround``, but *not* the ``reverse`` submodule, because it is shadowed by the locally defined ``reverse`` function::
__all__ = [
"echo", # refers to the 'echo.py' file
"surround", # refers to the 'surround.py' file
"reverse", # !!! refers to the 'reverse' func... | *`` would only import the two submodules ``echo`` and ``surround``, but *not* the ``reverse`` submodule, because it is shadowed by the locally defined ``reverse`` function::
__all__ = [
"echo", # refers to the 'echo.py' file
"surround", # refers to the 'surround.py' file
"reverse", # !!! refers to the 'reverse' func... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7828379a-974b-40ff-9410-1497bc205816 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,770 | supabase-export-v2 | 2a9fd5ceb328f5d1 | deserves some attention: :mod:`sys`, which is built into every Python interpreter. The variables ``sys.ps1`` and ``sys.ps2`` define the strings used as primary and secondary prompts::
>>> import sys
>>> sys.ps1
'>>> '
>>> sys.ps2
'... '
>>> sys.ps1 = 'C> '
C> print('Yuck!')
Yuck! C> | trusted_official_docs | CPython Docs | deserves some attention: :mod:`sys`, which is built into every Python interpreter. The variables ``sys.ps1`` and ``sys.ps2`` define the strings used as primary and secondary prompts::
>>> import sys
>>> sys.ps1
'>>> '
>>> sys.ps2
'... '
>>> sys.ps1 = 'C> '
C> print('Yuck!')
Yuck! C> | deserves some attention: :mod:`sys`, which is built into every Python interpreter. The variables ``sys.ps1`` and ``sys.ps2`` define the strings used as primary and secondary prompts::
>>> import sys
>>> sys.ps1
'>>> '
>>> sys.ps2
'... '
>>> sys.ps1 = 'C> '
C> print('Yuck!')
Yuck! C> | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7a7e599c-0871-4e1f-af6f-19aab3ea7885 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,708 | supabase-export-v2 | 49a5020e9ca8e671 | fib(n): """Write Fibonacci series up to n.""" a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print()
def fib2(n):
"""Return Fibonacci series up to n."""
result = []
a, b = 0, 1
while a < n:
result.append(a)
a, b = b, a+b
return result | trusted_official_docs | CPython Docs | fib(n): """Write Fibonacci series up to n.""" a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print()
def fib2(n):
"""Return Fibonacci series up to n."""
result = []
a, b = 0, 1
while a < n:
result.append(a)
a, b = b, a+b
return result | fib(n): """Write Fibonacci series up to n.""" a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print()
def fib2(n):
"""Return Fibonacci series up to n."""
result = []
a, b = 0, 1
while a < n:
result.append(a)
a, b = b, a+b
return result | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8248c84e-d9e6-4b49-8a68-b86956e1f64d | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,754 | supabase-export-v2 | 26460ac2055a65fb | input script is calculated after the symlink is followed. In other words the directory containing the symlink is **not** added to the module search path.
After initialization, Python programs can modify :data:`sys.path`. The
directory containing the script being run is placed at the beginning of the
search path, ahead ... | trusted_official_docs | CPython Docs | input script is calculated after the symlink is followed. In other words the directory containing the symlink is **not** added to the module search path.
After initialization, Python programs can modify :data:`sys.path`. The
directory containing the script being run is placed at the beginning of the
search path, ahead ... | input script is calculated after the symlink is followed. In other words the directory containing the symlink is **not** added to the module search path.
After initialization, Python programs can modify :data:`sys.path`. The
directory containing the script being run is placed at the beginning of the
search path, ahead ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
832f4793-e3fa-47ee-bbe3-25a1922f46f4 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,705 | supabase-export-v2 | 180c4e70c4d2a962 | into the *main* module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).
A module is a file containing Python definitions and statements. The file name
is the module name with the suffix :file:`.py` appended. Within a module, the
module's name (as a stri... | trusted_official_docs | CPython Docs | into the *main* module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).
A module is a file containing Python definitions and statements. The file name
is the module name with the suffix :file:`.py` appended. Within a module, the
module's name (as a stri... | into the *main* module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).
A module is a file containing Python definitions and statements. The file name
is the module name with the suffix :file:`.py` appended. Within a module, the
module's name (as a stri... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
89a7003c-75fc-40e4-9006-76a08f3f0a5e | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,719 | supabase-export-v2 | 9fadd4912647aac0 | if you know what you are doing you can touch a module's global variables with the same notation used to refer to its functions, ``modname.itemname``.
Modules can import other modules. It is customary but not required to place all
:keyword:`import` statements at the beginning of a module (or script, for that
matter). Th... | trusted_official_docs | CPython Docs | if you know what you are doing you can touch a module's global variables with the same notation used to refer to its functions, ``modname.itemname``.
Modules can import other modules. It is customary but not required to place all
:keyword:`import` statements at the beginning of a module (or script, for that
matter). Th... | if you know what you are doing you can touch a module's global variables with the same notation used to refer to its functions, ``modname.itemname``.
Modules can import other modules. It is customary but not required to place all
:keyword:`import` statements at the beginning of a module (or script, for that
matter). Th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8cbc349b-554a-41a9-97f3-85a7c8911ed4 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,809 | supabase-export-v2 | 601d667c4aa219c1 | them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.
The only solution is for the package author to provide an explicit index of the
package. The :keyword:`import` statement uses the following convention: if ... | trusted_official_docs | CPython Docs | them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.
The only solution is for the package author to provide an explicit index of the
package. The :keyword:`import` statement uses the following convention: if ... | them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.
The only solution is for the package author to provide an explicit index of the
package. The :keyword:`import` statement uses the following convention: if ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8d2ff21a-afb9-45b1-9c10-e5d902fea2b2 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,773 | supabase-export-v2 | 85f631bbd945b936 | path taken from the environment variable :envvar:`PYTHONPATH`, or from a built-in default if :envvar:`PYTHONPATH` is not set. You can modify it using standard list operations::
>>> import sys
>>> sys.path.append('/ufs/guido/lib/python') | trusted_official_docs | CPython Docs | path taken from the environment variable :envvar:`PYTHONPATH`, or from a built-in default if :envvar:`PYTHONPATH` is not set. You can modify it using standard list operations::
>>> import sys
>>> sys.path.append('/ufs/guido/lib/python') | path taken from the environment variable :envvar:`PYTHONPATH`, or from a built-in default if :envvar:`PYTHONPATH` is not set. You can modify it using standard list operations::
>>> import sys
>>> sys.path.append('/ufs/guido/lib/python') | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
955fa662-5c0c-4efe-b01e-848bd63b7c87 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,785 | supabase-export-v2 | 32e922cf06233561 | Packages ========
Packages are a way of structuring Python's module namespace by using "dotted
module names". For example, the module name :mod:`!A.B` designates a submodule
named ``B`` in a package named ``A``. Just like the use of modules saves the
authors of different modules from having to worry about each other's ... | trusted_official_docs | CPython Docs | Packages ========
Packages are a way of structuring Python's module namespace by using "dotted
module names". For example, the module name :mod:`!A.B` designates a submodule
named ``B`` in a package named ``A``. Just like the use of modules saves the
authors of different modules from having to worry about each other's ... | Packages ========
Packages are a way of structuring Python's module namespace by using "dotted
module names". For example, the module name :mod:`!A.B` designates a submodule
named ``B`` in a package named ``A``. Just like the use of modules saves the
authors of different modules from having to worry about each other's ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
987e37c9-a747-4073-a8da-8e903ee038b8 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,788 | supabase-export-v2 | 88cb8343056194e4 | .. code-block:: text
sound/ Top-level package
__init__.py Initialize the sound package
formats/ Subpackage for file format conversions
__init__.py
wavread.py
wavwrite.py
aiffread.py
aiffwrite.py
auread.py
auwrite.py
... effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
... ... | trusted_official_docs | CPython Docs | .. code-block:: text
sound/ Top-level package
__init__.py Initialize the sound package
formats/ Subpackage for file format conversions
__init__.py
wavread.py
wavwrite.py
aiffread.py
aiffwrite.py
auread.py
auwrite.py
... effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
... ... | .. code-block:: text
sound/ Top-level package
__init__.py Initialize the sound package
formats/ Subpackage for file format conversions
__init__.py
wavread.py
wavwrite.py
aiffread.py
aiffwrite.py
auread.py
auwrite.py
... effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
... ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
99ec1bf4-8746-47bf-bd77-daaf93ae5a23 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,711 | supabase-export-v2 | d59c1f02f224602a | >>> import fibo
This does not add the names of the functions defined in ``fibo`` directly to
the current :term:`namespace` (see :ref:`tut-scopes` for more details);
it only adds the module name ``fibo`` there. Using
the module name you can access the functions:: | trusted_official_docs | CPython Docs | >>> import fibo
This does not add the names of the functions defined in ``fibo`` directly to
the current :term:`namespace` (see :ref:`tut-scopes` for more details);
it only adds the module name ``fibo`` there. Using
the module name you can access the functions:: | >>> import fibo
This does not add the names of the functions defined in ``fibo`` directly to
the current :term:`namespace` (see :ref:`tut-scopes` for more details);
it only adds the module name ``fibo`` there. Using
the module name you can access the functions:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9c4f1fea-66c1-42b7-ad11-4a5124ce7fb8 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,815 | supabase-export-v2 | 552005c6cfb90455 | def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule return msg[::-1] # in the case of a 'from sound.effects import *'
If ``__all__`` is not defined, the statement ``from sound.effects import *``
does *not* import all submodules from the package :mod:`!sound.effects` into the
current namespace; it ... | trusted_official_docs | CPython Docs | def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule return msg[::-1] # in the case of a 'from sound.effects import *'
If ``__all__`` is not defined, the statement ``from sound.effects import *``
does *not* import all submodules from the package :mod:`!sound.effects` into the
current namespace; it ... | def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule return msg[::-1] # in the case of a 'from sound.effects import *'
If ``__all__`` is not defined, the statement ``from sound.effects import *``
does *not* import all submodules from the package :mod:`!sound.effects` into the
current namespace; it ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9d0e0081-3f79-4caa-83d0-62fcc3e31462 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,759 | supabase-export-v2 | 21fcb09702a511e0 | compiled version of spam.py would be cached as ``__pycache__/spam.cpython-33.pyc``. This naming convention allows compiled modules from different releases and different versions of Python to coexist.
Python checks the modification date of the source against the compiled version
to see if it's out of date and needs to b... | trusted_official_docs | CPython Docs | compiled version of spam.py would be cached as ``__pycache__/spam.cpython-33.pyc``. This naming convention allows compiled modules from different releases and different versions of Python to coexist.
Python checks the modification date of the source against the compiled version
to see if it's out of date and needs to b... | compiled version of spam.py would be cached as ``__pycache__/spam.cpython-33.pyc``. This naming convention allows compiled modules from different releases and different versions of Python to coexist.
Python checks the modification date of the source against the compiled version
to see if it's out of date and needs to b... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a1dcf845-936d-45c8-996f-1fd228d1db87 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,721 | supabase-export-v2 | 52354be5050bf0f1 | There is a variant of the :keyword:`import` statement that imports names from a module directly into the importing module's namespace. For example::
>>> from fibo import fib, fib2
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | trusted_official_docs | CPython Docs | There is a variant of the :keyword:`import` statement that imports names from a module directly into the importing module's namespace. For example::
>>> from fibo import fib, fib2
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | There is a variant of the :keyword:`import` statement that imports names from a module directly into the importing module's namespace. For example::
>>> from fibo import fib, fib2
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a3ce6ad4-686f-4d25-9973-35979b420da3 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,778 | supabase-export-v2 | d3245a70a627e282 | 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'unrai... | trusted_official_docs | CPython Docs | 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'unrai... | 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'unrai... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a609c183-70d1-41d4-8557-2f8352a0ff8e | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,783 | supabase-export-v2 | 4b6307457a1f0ce4 | does not list the names of built-in functions and variables. If you want a list of those, they are defined in the standard module :mod:`builtins`::
>>> import builtins
>>> dir(builtins) # doctest: +NORMALIZE_WHITESPACE
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',
'BlockingIOError', 'Broke... | trusted_official_docs | CPython Docs | does not list the names of built-in functions and variables. If you want a list of those, they are defined in the standard module :mod:`builtins`::
>>> import builtins
>>> dir(builtins) # doctest: +NORMALIZE_WHITESPACE
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',
'BlockingIOError', 'Broke... | does not list the names of built-in functions and variables. If you want a list of those, they are defined in the standard module :mod:`builtins`::
>>> import builtins
>>> dir(builtins) # doctest: +NORMALIZE_WHITESPACE
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',
'BlockingIOError', 'Broke... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a8d4b670-ba0b-45e6-9f9f-e96c5d498b1d | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,762 | supabase-export-v2 | 83e753424fbb70b4 | Some tips for experts:
* You can use the :option:`-O` or :option:`-OO` switches on the Python command
to reduce the size of a compiled module. The ``-O`` switch removes assert
statements, the ``-OO`` switch removes both assert statements and __doc__
strings. Since some programs may rely on having these available, yo... | trusted_official_docs | CPython Docs | Some tips for experts:
* You can use the :option:`-O` or :option:`-OO` switches on the Python command
to reduce the size of a compiled module. The ``-O`` switch removes assert
statements, the ``-OO`` switch removes both assert statements and __doc__
strings. Since some programs may rely on having these available, yo... | Some tips for experts:
* You can use the :option:`-O` or :option:`-OO` switches on the Python command
to reduce the size of a compiled module. The ``-O`` switch removes assert
statements, the ``-OO`` switch removes both assert statements and __doc__
strings. Since some programs may rely on having these available, yo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bbeb8a8f-0dd6-4ca2-bd12-28dfda3d4737 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,734 | supabase-export-v2 | 70511ed96bd20c93 | .. note::
For efficiency reasons, each module is only imported once per interpreter
session. Therefore, if you change your modules, you must restart the
interpreter -- or, if it's just one module you want to test interactively,
use :func:`importlib.reload`, e.g. ``import importlib;
importlib.reload(modulename)``. | trusted_official_docs | CPython Docs | .. note::
For efficiency reasons, each module is only imported once per interpreter
session. Therefore, if you change your modules, you must restart the
interpreter -- or, if it's just one module you want to test interactively,
use :func:`importlib.reload`, e.g. ``import importlib;
importlib.reload(modulename)``. | .. note::
For efficiency reasons, each module is only imported once per interpreter
session. Therefore, if you change your modules, you must restart the
interpreter -- or, if it's just one module you want to test interactively,
use :func:`importlib.reload`, e.g. ``import importlib;
importlib.reload(modulename)``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cc043b61-d47c-4e0b-bad9-34dbcc0cdf59 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,827 | supabase-export-v2 | b1cbfb4f39688744 | Packages in Multiple Directories --------------------------------
Packages support one more special attribute, :attr:`~module.__path__`. This is
initialized to be a :term:`sequence` of strings containing the name of the
directory holding the
package's :file:`__init__.py` before the code in that file is executed. This
v... | trusted_official_docs | CPython Docs | Packages in Multiple Directories --------------------------------
Packages support one more special attribute, :attr:`~module.__path__`. This is
initialized to be a :term:`sequence` of strings containing the name of the
directory holding the
package's :file:`__init__.py` before the code in that file is executed. This
v... | Packages in Multiple Directories --------------------------------
Packages support one more special attribute, :attr:`~module.__path__`. This is
initialized to be a :term:`sequence` of strings containing the name of the
directory holding the
package's :file:`__init__.py` before the code in that file is executed. This
v... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d25b5e1f-a692-48fd-a1ab-17fdcce82f68 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,753 | supabase-export-v2 | 983a1843047097ae | More details are at :ref:`sys-path-init`.
.. note::
On file systems which support symlinks, the directory containing the input
script is calculated after the symlink is followed. In other words the
directory containing the symlink is **not** added to the module search path. | trusted_official_docs | CPython Docs | More details are at :ref:`sys-path-init`.
.. note::
On file systems which support symlinks, the directory containing the input
script is calculated after the symlink is followed. In other words the
directory containing the symlink is **not** added to the module search path. | More details are at :ref:`sys-path-init`.
.. note::
On file systems which support symlinks, the directory containing the input
script is calculated after the symlink is followed. In other words the
directory containing the symlink is **not** added to the module search path. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d29d2d21-b4e4-4816-905e-7d530643d32e | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,814 | supabase-export-v2 | 745606e32084d6b1 | "echo", # refers to the 'echo.py' file "surround", # refers to the 'surround.py' file "reverse", # !!! refers to the 'reverse' function now !!! ]
def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule
return msg[::-1] # in the case of a 'from sound.effects import *' | trusted_official_docs | CPython Docs | "echo", # refers to the 'echo.py' file "surround", # refers to the 'surround.py' file "reverse", # !!! refers to the 'reverse' function now !!! ]
def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule
return msg[::-1] # in the case of a 'from sound.effects import *' | "echo", # refers to the 'echo.py' file "surround", # refers to the 'surround.py' file "reverse", # !!! refers to the 'reverse' function now !!! ]
def reverse(msg: str): # <-- this name shadows the 'reverse.py' submodule
return msg[::-1] # in the case of a 'from sound.effects import *' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dbdf58de-94db-42fa-bf16-d02c13e18a9f | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,703 | supabase-export-v2 | 75ba327e68f9a622 | ******* Modules *******
If you quit from the Python interpreter and enter it again, the definitions you
have made (functions and variables) are lost. Therefore, if you want to write a
somewhat longer program, you are better off using a text editor to prepare the
input for the interpreter and running it with that file a... | trusted_official_docs | CPython Docs | ******* Modules *******
If you quit from the Python interpreter and enter it again, the definitions you
have made (functions and variables) are lost. Therefore, if you want to write a
somewhat longer program, you are better off using a text editor to prepare the
input for the interpreter and running it with that file a... | ******* Modules *******
If you quit from the Python interpreter and enter it again, the definitions you
have made (functions and variables) are lost. Therefore, if you want to write a
somewhat longer program, you are better off using a text editor to prepare the
input for the interpreter and running it with that file a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e1b25427-8995-4277-9fa5-e0bb2ff77144 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,790 | supabase-export-v2 | 53dc3b1dbdd2b720 | When importing the package, Python searches through the directories on ``sys.path`` looking for the package subdirectory.
The :file:`__init__.py` files are required to make Python treat directories
containing the file as packages (unless using a :term:`namespace package`, a
relatively advanced feature). This prevents d... | trusted_official_docs | CPython Docs | When importing the package, Python searches through the directories on ``sys.path`` looking for the package subdirectory.
The :file:`__init__.py` files are required to make Python treat directories
containing the file as packages (unless using a :term:`namespace package`, a
relatively advanced feature). This prevents d... | When importing the package, Python searches through the directories on ``sys.path`` looking for the package subdirectory.
The :file:`__init__.py` files are required to make Python treat directories
containing the file as packages (unless using a :term:`namespace package`, a
relatively advanced feature). This prevents d... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e2e315ab-9df1-47d6-b584-d2d34bdaf2b1 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,772 | supabase-export-v2 | fefef00df5170bee | These two variables are only defined if the interpreter is in interactive mode.
The variable ``sys.path`` is a list of strings that determines the interpreter's
search path for modules. It is initialized to a default path taken from the
environment variable :envvar:`PYTHONPATH`, or from a built-in default if
:envvar:`P... | trusted_official_docs | CPython Docs | These two variables are only defined if the interpreter is in interactive mode.
The variable ``sys.path`` is a list of strings that determines the interpreter's
search path for modules. It is initialized to a default path taken from the
environment variable :envvar:`PYTHONPATH`, or from a built-in default if
:envvar:`P... | These two variables are only defined if the interpreter is in interactive mode.
The variable ``sys.path`` is a list of strings that determines the interpreter's
search path for modules. It is initialized to a default path taken from the
environment variable :envvar:`PYTHONPATH`, or from a built-in default if
:envvar:`P... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e5cda1b4-7a1c-4d3f-b5c4-1ffba3219cf5 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,755 | supabase-export-v2 | e82c492afce87538 | of modules of the same name in the library directory. This is an error unless the replacement is intended. See section :ref:`tut-standardmodules` for more information.
.. %
Do we need stuff on zip files etc. ? DUBOIS | trusted_official_docs | CPython Docs | of modules of the same name in the library directory. This is an error unless the replacement is intended. See section :ref:`tut-standardmodules` for more information.
.. %
Do we need stuff on zip files etc. ? DUBOIS | of modules of the same name in the library directory. This is an error unless the replacement is intended. See section :ref:`tut-standardmodules` for more information.
.. %
Do we need stuff on zip files etc. ? DUBOIS | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e6fb694f-0230-40d0-bd8e-9d8df249582f | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,720 | supabase-export-v2 | 787593258d376ee8 | The imported module names, if placed at the top level of a module (outside any functions or classes), are added to the module's global namespace.
There is a variant of the :keyword:`import` statement that imports names from a
module directly into the importing module's namespace. For example:: | trusted_official_docs | CPython Docs | The imported module names, if placed at the top level of a module (outside any functions or classes), are added to the module's global namespace.
There is a variant of the :keyword:`import` statement that imports names from a
module directly into the importing module's namespace. For example:: | The imported module names, if placed at the top level of a module (outside any functions or classes), are added to the module's global namespace.
There is a variant of the :keyword:`import` statement that imports names from a
module directly into the importing module's namespace. For example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e710ae02-c595-46ae-bf30-29ec84554c81 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,724 | supabase-export-v2 | 5cd6a6bcb9346108 | There is even a variant to import all names that a module defines::
>>> from fibo import *
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | trusted_official_docs | CPython Docs | There is even a variant to import all names that a module defines::
>>> from fibo import *
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | There is even a variant to import all names that a module defines::
>>> from fibo import *
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e93f2ed8-2985-4934-a7ba-29a5c3b2d15f | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,740 | supabase-export-v2 | c752248e2dd6e01f | as if you imported it, but with the ``__name__`` set to ``"__main__"``. That means that by adding this code at the end of your module::
if __name__ == "__main__":
import sys
fib(int(sys.argv[1])) | trusted_official_docs | CPython Docs | as if you imported it, but with the ``__name__`` set to ``"__main__"``. That means that by adding this code at the end of your module::
if __name__ == "__main__":
import sys
fib(int(sys.argv[1])) | as if you imported it, but with the ``__name__`` set to ``"__main__"``. That means that by adding this code at the end of your module::
if __name__ == "__main__":
import sys
fib(int(sys.argv[1])) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ef883961-a4c1-49c4-81d2-e1a1aa46b011 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,786 | supabase-export-v2 | aeccdc1a02d31400 | the use of dotted module names saves the authors of multi-module packages like NumPy or Pillow from having to worry about each other's module names.
Suppose you want to design a collection of modules (a "package") for the uniform
handling of sound files and sound data. There are many different sound file
formats (usual... | trusted_official_docs | CPython Docs | the use of dotted module names saves the authors of multi-module packages like NumPy or Pillow from having to worry about each other's module names.
Suppose you want to design a collection of modules (a "package") for the uniform
handling of sound files and sound data. There are many different sound file
formats (usual... | the use of dotted module names saves the authors of multi-module packages like NumPy or Pillow from having to worry about each other's module names.
Suppose you want to design a collection of modules (a "package") for the uniform
handling of sound files and sound data. There are many different sound file
formats (usual... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f15a1973-0628-4610-82e4-cc9035381989 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,782 | supabase-export-v2 | 96a2c593ca69a493 | .. index:: pair: module; builtins
:func:`dir` does not list the names of built-in functions and variables. If you
want a list of those, they are defined in the standard module
:mod:`builtins`:: | trusted_official_docs | CPython Docs | .. index:: pair: module; builtins
:func:`dir` does not list the names of built-in functions and variables. If you
want a list of those, they are defined in the standard module
:mod:`builtins`:: | .. index:: pair: module; builtins
:func:`dir` does not list the names of built-in functions and variables. If you
want a list of those, they are defined in the standard module
:mod:`builtins`:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f2ba2d5c-f042-4c92-842f-5b1206c2bf7c | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,791 | supabase-export-v2 | d6d65f2b5ac5520c | case, :file:`__init__.py` can just be an empty file, but it can also execute initialization code for the package or set the ``__all__`` variable, described later.
Users of the package can import individual modules from the package, for
example:: | trusted_official_docs | CPython Docs | case, :file:`__init__.py` can just be an empty file, but it can also execute initialization code for the package or set the ``__all__`` variable, described later.
Users of the package can import individual modules from the package, for
example:: | case, :file:`__init__.py` can just be an empty file, but it can also execute initialization code for the package or set the ``__all__`` variable, described later.
Users of the package can import individual modules from the package, for
example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f4b48045-1b16-41f1-a536-316d510feb62 | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,707 | supabase-export-v2 | e0b6fb5c6f38f976 | # Fibonacci numbers module
def fib(n):
"""Write Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print() | trusted_official_docs | CPython Docs | # Fibonacci numbers module
def fib(n):
"""Write Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print() | # Fibonacci numbers module
def fib(n):
"""Write Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print() | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f5663a81-3fe0-4d24-b926-27254f9dcebc | CPython Docs | file://datasets/cpython/Doc/tutorial/modules.rst | unknown | b861e0bf-b87a-48ad-9627-b6822a304bc5 | 53,704 | supabase-export-v2 | 4baa35437e6c5368 | for easier maintenance. You may also want to use a handy function that you've written in several programs without copying its definition into each program.
To support this, Python has a way to put definitions in a file and use them in a
script or in an interactive instance of the interpreter. Such a file is called a
*m... | trusted_official_docs | CPython Docs | for easier maintenance. You may also want to use a handy function that you've written in several programs without copying its definition into each program.
To support this, Python has a way to put definitions in a file and use them in a
script or in an interactive instance of the interpreter. Such a file is called a
*m... | for easier maintenance. You may also want to use a handy function that you've written in several programs without copying its definition into each program.
To support this, Python has a way to put definitions in a file and use them in a
script or in an interactive instance of the interpreter. Such a file is called a
*m... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
00c46b11-1953-4b48-bda1-f4cd77652490 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,877 | supabase-export-v2 | 25c06a16567820e3 | (or overwrites) a variable named ``x`` that still exists after the loop completes. We can calculate the list of squares without any side effects using::
squares = list(map(lambda x: x**2, range(10))) | trusted_official_docs | CPython Docs | (or overwrites) a variable named ``x`` that still exists after the loop completes. We can calculate the list of squares without any side effects using::
squares = list(map(lambda x: x**2, range(10))) | (or overwrites) a variable named ``x`` that still exists after the loop completes. We can calculate the list of squares without any side effects using::
squares = list(map(lambda x: x**2, range(10))) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
039fc929-9823-48e4-a971-3957f3c0eb8a | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,950 | supabase-export-v2 | 837c004cbc860414 | Here is a small example using a dictionary::
>>> tel = {'jack': 4098, 'sape': 4139}
>>> tel['guido'] = 4127
>>> tel
{'jack': 4098, 'sape': 4139, 'guido': 4127}
>>> tel['jack']
4098
>>> tel['irv']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'irv'
>>> print(tel.get('irv'))
... | trusted_official_docs | CPython Docs | Here is a small example using a dictionary::
>>> tel = {'jack': 4098, 'sape': 4139}
>>> tel['guido'] = 4127
>>> tel
{'jack': 4098, 'sape': 4139, 'guido': 4127}
>>> tel['jack']
4098
>>> tel['irv']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'irv'
>>> print(tel.get('irv'))
... | Here is a small example using a dictionary::
>>> tel = {'jack': 4098, 'sape': 4139}
>>> tel['guido'] = 4127
>>> tel
{'jack': 4098, 'sape': 4139, 'guido': 4127}
>>> tel['jack']
4098
>>> tel['irv']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'irv'
>>> print(tel.get('irv'))
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
04f4f127-dc33-4fcc-905f-375d7a751be7 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,896 | supabase-export-v2 | 7d21cdf3a94f0190 | The following list comprehension will transpose rows and columns::
>>> [[row[i] for row in matrix] for i in range(4)]
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] | trusted_official_docs | CPython Docs | The following list comprehension will transpose rows and columns::
>>> [[row[i] for row in matrix] for i in range(4)]
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] | The following list comprehension will transpose rows and columns::
>>> [[row[i] for row in matrix] for i in range(4)]
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
08212131-e2f7-440d-83ae-c40f311d8cd3 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,849 | supabase-export-v2 | 24337cf867fa2132 | Return zero-based index of the first occurrence of *value* in the list. Raises a :exc:`ValueError` if there is no such item.
The optional arguments *start* and *end* are interpreted as in the slice
notation and are used to limit the search to a particular subsequence of
the list. The returned index is computed relati... | trusted_official_docs | CPython Docs | Return zero-based index of the first occurrence of *value* in the list. Raises a :exc:`ValueError` if there is no such item.
The optional arguments *start* and *end* are interpreted as in the slice
notation and are used to limit the search to a particular subsequence of
the list. The returned index is computed relati... | Return zero-based index of the first occurrence of *value* in the list. Raises a :exc:`ValueError` if there is no such item.
The optional arguments *start* and *end* are interpreted as in the slice
notation and are used to limit the search to a particular subsequence of
the list. The returned index is computed relati... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
08d9d999-9db3-4eed-805c-6812cdeaba61 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,886 | supabase-export-v2 | 2c6602624430f0d5 | Note how the order of the :keyword:`for` and :keyword:`if` statements is the same in both these snippets.
If the expression is a tuple (e.g. the ``(x, y)`` in the previous example),
it must be parenthesized. :: | trusted_official_docs | CPython Docs | Note how the order of the :keyword:`for` and :keyword:`if` statements is the same in both these snippets.
If the expression is a tuple (e.g. the ``(x, y)`` in the previous example),
it must be parenthesized. :: | Note how the order of the :keyword:`for` and :keyword:`if` statements is the same in both these snippets.
If the expression is a tuple (e.g. the ``(x, y)`` in the previous example),
it must be parenthesized. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0e666ea0-dc52-4e42-96b5-b9bcc838f96c | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,889 | supabase-export-v2 | 37e9ff94f4ba55c3 | >>> vec = [[1,2,3], [4,5,6], [7,8,9]] >>> [num for elem in vec for num in elem] [1, 2, 3, 4, 5, 6, 7, 8, 9]
List comprehensions can contain complex expressions and nested functions:: | trusted_official_docs | CPython Docs | >>> vec = [[1,2,3], [4,5,6], [7,8,9]] >>> [num for elem in vec for num in elem] [1, 2, 3, 4, 5, 6, 7, 8, 9]
List comprehensions can contain complex expressions and nested functions:: | >>> vec = [[1,2,3], [4,5,6], [7,8,9]] >>> [num for elem in vec for num in elem] [1, 2, 3, 4, 5, 6, 7, 8, 9]
List comprehensions can contain complex expressions and nested functions:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1262ed2d-74ea-403b-9fb0-00ffc4939727 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,882 | supabase-export-v2 | 27be38104f49cba9 | context of the :keyword:`!for` and :keyword:`!if` clauses which follow it. For example, this listcomp combines the elements of two lists if they are not equal::
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)] | trusted_official_docs | CPython Docs | context of the :keyword:`!for` and :keyword:`!if` clauses which follow it. For example, this listcomp combines the elements of two lists if they are not equal::
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)] | context of the :keyword:`!for` and :keyword:`!if` clauses which follow it. For example, this listcomp combines the elements of two lists if they are not equal::
>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1719c7ec-f58d-473f-a2e2-74c619307afa | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,924 | supabase-export-v2 | ba3ec2492dea229a | (see :ref:`typesseq`). Since Python is an evolving language, other sequence data types may be added. There is also another standard sequence data type: the *tuple*.
A tuple consists of a number of values separated by commas, for instance:: | trusted_official_docs | CPython Docs | (see :ref:`typesseq`). Since Python is an evolving language, other sequence data types may be added. There is also another standard sequence data type: the *tuple*.
A tuple consists of a number of values separated by commas, for instance:: | (see :ref:`typesseq`). Since Python is an evolving language, other sequence data types may be added. There is also another standard sequence data type: the *tuple*.
A tuple consists of a number of values separated by commas, for instance:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
17bfdd90-9ba2-4169-8ff8-32cecac75ecc | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,918 | supabase-export-v2 | 8f5ffc342c618294 | 1234.5] >>> del a[0] >>> a [1, 66.25, 333, 333, 1234.5] >>> del a[2:4] >>> a [1, 66.25, 1234.5] >>> del a[:] >>> a []
:keyword:`del` can also be used to delete entire variables:: | trusted_official_docs | CPython Docs | 1234.5] >>> del a[0] >>> a [1, 66.25, 333, 333, 1234.5] >>> del a[2:4] >>> a [1, 66.25, 1234.5] >>> del a[:] >>> a []
:keyword:`del` can also be used to delete entire variables:: | 1234.5] >>> del a[0] >>> a [1, 66.25, 333, 333, 1234.5] >>> del a[2:4] >>> a [1, 66.25, 1234.5] >>> del a[:] >>> a []
:keyword:`del` can also be used to delete entire variables:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1b000609-7f1a-4da1-9587-83c7d7773fe1 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,939 | supabase-export-v2 | 50cc07c4aa39ecba | # show that duplicates have been removed {'orange', 'banana', 'pear', 'apple'} >>> 'orange' in basket # fast membership testing True >>> 'crabgrass' in basket False
>>> # Demonstrate set operations on unique letters from two words
>>>
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a # unique letters in a
{... | trusted_official_docs | CPython Docs | # show that duplicates have been removed {'orange', 'banana', 'pear', 'apple'} >>> 'orange' in basket # fast membership testing True >>> 'crabgrass' in basket False
>>> # Demonstrate set operations on unique letters from two words
>>>
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a # unique letters in a
{... | # show that duplicates have been removed {'orange', 'banana', 'pear', 'apple'} >>> 'orange' in basket # fast membership testing True >>> 'crabgrass' in basket False
>>> # Demonstrate set operations on unique letters from two words
>>>
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a # unique letters in a
{... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1bcb8ddf-0a2a-4423-b06b-402152f59c98 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,859 | supabase-export-v2 | 80f91f4e148e2c51 | An example that uses most of the list methods::
>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> fruits.count('apple')
2
>>> fruits.count('tangerine')
0
>>> fruits.index('banana')
3
>>> fruits.index('banana', 4) # Find next banana starting at position 4
6
>>> fruits.reverse()
... | trusted_official_docs | CPython Docs | An example that uses most of the list methods::
>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> fruits.count('apple')
2
>>> fruits.count('tangerine')
0
>>> fruits.index('banana')
3
>>> fruits.index('banana', 4) # Find next banana starting at position 4
6
>>> fruits.reverse()
... | An example that uses most of the list methods::
>>> fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
>>> fruits.count('apple')
2
>>> fruits.count('tangerine')
0
>>> fruits.index('banana')
3
>>> fruits.index('banana', 4) # Find next banana starting at position 4
6
>>> fruits.reverse()
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1d551939-f08b-451d-bfd0-d5288d0dca4d | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,979 | supabase-export-v2 | 4ecfcbbd36bdb938 | The conditions used in ``while`` and ``if`` statements can contain any operators, not just comparisons.
The comparison operators ``in`` and ``not in`` are membership tests that
determine whether a value is in (or not in) a container. The operators ``is``
and ``is not`` compare whether two objects are really the same ob... | trusted_official_docs | CPython Docs | The conditions used in ``while`` and ``if`` statements can contain any operators, not just comparisons.
The comparison operators ``in`` and ``not in`` are membership tests that
determine whether a value is in (or not in) a container. The operators ``is``
and ``is not`` compare whether two objects are really the same ob... | The conditions used in ``while`` and ``if`` statements can contain any operators, not just comparisons.
The comparison operators ``in`` and ``not in`` are membership tests that
determine whether a value is in (or not in) a container. The operators ``is``
and ``is not`` compare whether two objects are really the same ob... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
227a232c-7ec5-436e-ba5f-77334bdd0cfc | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,873 | supabase-export-v2 | f4bd9da9f2ae8c10 | List Comprehensions -------------------
List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of
some operations applied to each member of another sequence or iterable, or to
create a subsequence of those elements that satisfy a certain con... | trusted_official_docs | CPython Docs | List Comprehensions -------------------
List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of
some operations applied to each member of another sequence or iterable, or to
create a subsequence of those elements that satisfy a certain con... | List Comprehensions -------------------
List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of
some operations applied to each member of another sequence or iterable, or to
create a subsequence of those elements that satisfy a certain con... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
24328d57-86eb-44c0-a5ea-19414b475291 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,864 | supabase-export-v2 | f364566b6f930a72 | Using Lists as Stacks ---------------------
The list methods make it very easy to use a list as a stack, where the last
element added is the first element retrieved ("last-in, first-out"). To add an
item to the top of the stack, use :meth:`~list.append`. To retrieve an item from the
top of the stack, use :meth:`~list.p... | trusted_official_docs | CPython Docs | Using Lists as Stacks ---------------------
The list methods make it very easy to use a list as a stack, where the last
element added is the first element retrieved ("last-in, first-out"). To add an
item to the top of the stack, use :meth:`~list.append`. To retrieve an item from the
top of the stack, use :meth:`~list.p... | Using Lists as Stacks ---------------------
The list methods make it very easy to use a list as a stack, where the last
element added is the first element retrieved ("last-in, first-out"). To add an
item to the top of the stack, use :meth:`~list.append`. To retrieve an item from the
top of the stack, use :meth:`~list.p... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2507f1eb-a862-4489-9ac4-9aaf97d5e7de | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,902 | supabase-export-v2 | 72afb29fcf74484b | In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case::
>>> list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] | trusted_official_docs | CPython Docs | In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case::
>>> list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] | In the real world, you should prefer built-in functions to complex flow statements. The :func:`zip` function would do a great job for this use case::
>>> list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
276413e5-6dd3-44ce-85a3-06a38a7751de | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,963 | supabase-export-v2 | b5cee4cf1a0921ba | When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the :meth:`~dict.items` method. ::
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.items():
... print(k, v)
... gallahad the pure
robin the brave | trusted_official_docs | CPython Docs | When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the :meth:`~dict.items` method. ::
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.items():
... print(k, v)
... gallahad the pure
robin the brave | When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the :meth:`~dict.items` method. ::
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.items():
... print(k, v)
... gallahad the pure
robin the brave | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
29c65d18-0178-46f9-8f15-787fa78e6b14 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,850 | supabase-export-v2 | 21e3c097067843f5 | to a particular subsequence of the list. The returned index is computed relative to the beginning of the full sequence rather than the *start* argument.
.. method:: list.count(value, /)
:noindex: | trusted_official_docs | CPython Docs | to a particular subsequence of the list. The returned index is computed relative to the beginning of the full sequence rather than the *start* argument.
.. method:: list.count(value, /)
:noindex: | to a particular subsequence of the list. The returned index is computed relative to the beginning of the full sequence rather than the *start* argument.
.. method:: list.count(value, /)
:noindex: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2a0709de-246c-4725-977b-a5d3fe753823 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,957 | supabase-export-v2 | b15d33b28048c74b | evens = {i: i**2 for i in (2, 4, 6)} >>> {**odds, **evens} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36}
>>> all_values = [odds, evens, {0: 0}]
>>> {**i for i in all_values}
{1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36, 0: 0} | trusted_official_docs | CPython Docs | evens = {i: i**2 for i in (2, 4, 6)} >>> {**odds, **evens} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36}
>>> all_values = [odds, evens, {0: 0}]
>>> {**i for i in all_values}
{1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36, 0: 0} | evens = {i: i**2 for i in (2, 4, 6)} >>> {**odds, **evens} {1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36}
>>> all_values = [odds, evens, {0: 0}]
>>> {**i for i in all_values}
{1: 1, 3: 9, 5: 25, 2: 4, 4: 16, 6: 36, 0: 0} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2c57301f-4c65-4a36-b4d7-f16dd0587ed8 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,949 | supabase-export-v2 | 49a06d4f07770bbc | insertion order (if you want it sorted, just use ``sorted(d)`` instead). To check whether a single key is in the dictionary, use the :keyword:`in` keyword.
Here is a small example using a dictionary:: | trusted_official_docs | CPython Docs | insertion order (if you want it sorted, just use ``sorted(d)`` instead). To check whether a single key is in the dictionary, use the :keyword:`in` keyword.
Here is a small example using a dictionary:: | insertion order (if you want it sorted, just use ``sorted(d)`` instead). To check whether a single key is in the dictionary, use the :keyword:`in` keyword.
Here is a small example using a dictionary:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2e6583e5-10d4-4364-80b9-4e09f3332c22 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,907 | supabase-export-v2 | c5336afc3b2dd313 | >>> x = [1, 2, 3] >>> [0, *x, 4, 5, 6] [0, 1, 2, 3, 4, 5, 6]
This only works if the expression following the ``*`` evaluates to an iterable
object; trying to unpack a non-iterable object will raise an exception:: | trusted_official_docs | CPython Docs | >>> x = [1, 2, 3] >>> [0, *x, 4, 5, 6] [0, 1, 2, 3, 4, 5, 6]
This only works if the expression following the ``*`` evaluates to an iterable
object; trying to unpack a non-iterable object will raise an exception:: | >>> x = [1, 2, 3] >>> [0, *x, 4, 5, 6] [0, 1, 2, 3, 4, 5, 6]
This only works if the expression following the ``*`` evaluates to an iterable
object; trying to unpack a non-iterable object will raise an exception:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2f463431-ec83-4f90-990e-572c6eee4906 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,895 | supabase-export-v2 | ca594c481759b4c6 | >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ]
The following list comprehension will transpose rows and columns:: | trusted_official_docs | CPython Docs | >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ]
The following list comprehension will transpose rows and columns:: | >>> matrix = [ ... [1, 2, 3, 4], ... [5, 6, 7, 8], ... [9, 10, 11, 12], ... ]
The following list comprehension will transpose rows and columns:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33dcce9c-6ff0-4eb2-90c6-fd1fe11aa1f7 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,928 | supabase-export-v2 | c2863a43b6e317c5 | by attribute in the case of :func:`namedtuples <collections.namedtuple>`). Lists are :term:`mutable`, and their elements are usually homogeneous and are accessed by iterating over the list.
A special problem is the construction of tuples containing 0 or 1 items: the
syntax has some extra quirks to accommodate these. Em... | trusted_official_docs | CPython Docs | by attribute in the case of :func:`namedtuples <collections.namedtuple>`). Lists are :term:`mutable`, and their elements are usually homogeneous and are accessed by iterating over the list.
A special problem is the construction of tuples containing 0 or 1 items: the
syntax has some extra quirks to accommodate these. Em... | by attribute in the case of :func:`namedtuples <collections.namedtuple>`). Lists are :term:`mutable`, and their elements are usually homogeneous and are accessed by iterating over the list.
A special problem is the construction of tuples containing 0 or 1 items: the
syntax has some extra quirks to accommodate these. Em... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3cb78c15-2815-4d95-885f-c5cbbc46c2d8 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,840 | supabase-export-v2 | 94fe010a5700a766 | .. method:: list.insert(index, value, /) :noindex:
Insert an item at a given position. The first argument is the index of the
element before which to insert, so ``a.insert(0, x)`` inserts at the front of
the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``. | trusted_official_docs | CPython Docs | .. method:: list.insert(index, value, /) :noindex:
Insert an item at a given position. The first argument is the index of the
element before which to insert, so ``a.insert(0, x)`` inserts at the front of
the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``. | .. method:: list.insert(index, value, /) :noindex:
Insert an item at a given position. The first argument is the index of the
element before which to insert, so ``a.insert(0, x)`` inserts at the front of
the list, and ``a.insert(len(a), x)`` is equivalent to ``a.append(x)``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3cc7b0d6-ad40-4643-8a4e-28e98078e9cd | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,865 | supabase-export-v2 | 7db13df556e83c14 | the top of the stack, use :meth:`~list.append`. To retrieve an item from the top of the stack, use :meth:`~list.pop` without an explicit index. For example::
>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
[3, 4, 5, 6, 7]
>>> stack.pop()
7
>>> stack
[3, 4, 5, 6]
>>> stack.pop()
6
>>> ... | trusted_official_docs | CPython Docs | the top of the stack, use :meth:`~list.append`. To retrieve an item from the top of the stack, use :meth:`~list.pop` without an explicit index. For example::
>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
[3, 4, 5, 6, 7]
>>> stack.pop()
7
>>> stack
[3, 4, 5, 6]
>>> stack.pop()
6
>>> ... | the top of the stack, use :meth:`~list.append`. To retrieve an item from the top of the stack, use :meth:`~list.pop` without an explicit index. For example::
>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
[3, 4, 5, 6, 7]
>>> stack.pop()
7
>>> stack
[3, 4, 5, 6]
>>> stack.pop()
6
>>> ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3e0b0644-68f1-429a-ba15-7d60ba6e224b | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,912 | supabase-export-v2 | 003c2921d4f23038 | Note that the effect is that each element from ``x`` is unpacked. This works for arbitrary iterable objects, not just lists::
>>> x = [[1, 2, 3], 'cat', {'spam': 'eggs'}]
>>> [*element for element in x]
[1, 2, 3, 'c', 'a', 't', 'spam'] | trusted_official_docs | CPython Docs | Note that the effect is that each element from ``x`` is unpacked. This works for arbitrary iterable objects, not just lists::
>>> x = [[1, 2, 3], 'cat', {'spam': 'eggs'}]
>>> [*element for element in x]
[1, 2, 3, 'c', 'a', 't', 'spam'] | Note that the effect is that each element from ``x`` is unpacked. This works for arbitrary iterable objects, not just lists::
>>> x = [[1, 2, 3], 'cat', {'spam': 'eggs'}]
>>> [*element for element in x]
[1, 2, 3, 'c', 'a', 't', 'spam'] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3e4272fb-a29c-46a2-b07b-4740f31ac23c | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,971 | supabase-export-v2 | cbef7b90f2749c68 | To loop over a sequence in sorted order, use the :func:`sorted` function which returns a new sorted list while leaving the source unaltered. ::
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> for i in sorted(basket):
... print(i)
... apple
apple
banana
orange
orange
pear | trusted_official_docs | CPython Docs | To loop over a sequence in sorted order, use the :func:`sorted` function which returns a new sorted list while leaving the source unaltered. ::
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> for i in sorted(basket):
... print(i)
... apple
apple
banana
orange
orange
pear | To loop over a sequence in sorted order, use the :func:`sorted` function which returns a new sorted list while leaving the source unaltered. ::
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> for i in sorted(basket):
... print(i)
... apple
apple
banana
orange
orange
pear | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
47de162c-71e6-4bb4-a58c-b39a4bd84533 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,936 | supabase-export-v2 | 81f4aeb7408d4873 | empty set you have to use ``set()``, not ``{}``; the latter creates an empty dictionary, a data structure that we discuss in the next section.
Because sets are unordered, iterating over them or printing them can
produce the elements in a different order than you expect. | trusted_official_docs | CPython Docs | empty set you have to use ``set()``, not ``{}``; the latter creates an empty dictionary, a data structure that we discuss in the next section.
Because sets are unordered, iterating over them or printing them can
produce the elements in a different order than you expect. | empty set you have to use ``set()``, not ``{}``; the latter creates an empty dictionary, a data structure that we discuss in the next section.
Because sets are unordered, iterating over them or printing them can
produce the elements in a different order than you expect. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
49679e7d-5611-40db-8d38-90e9b03cac89 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,930 | supabase-export-v2 | aa9e893044bcb260 | >>> empty = () >>> singleton = 'hello', # <-- note trailing comma >>> len(empty) 0 >>> len(singleton) 1 >>> singleton ('hello',)
The statement ``t = 12345, 54321, 'hello!'`` is an example of *tuple packing*:
the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple. The reverse operation is also p... | trusted_official_docs | CPython Docs | >>> empty = () >>> singleton = 'hello', # <-- note trailing comma >>> len(empty) 0 >>> len(singleton) 1 >>> singleton ('hello',)
The statement ``t = 12345, 54321, 'hello!'`` is an example of *tuple packing*:
the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple. The reverse operation is also p... | >>> empty = () >>> singleton = 'hello', # <-- note trailing comma >>> len(empty) 0 >>> len(singleton) 1 >>> singleton ('hello',)
The statement ``t = 12345, 54321, 'hello!'`` is an example of *tuple packing*:
the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple. The reverse operation is also p... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4ae770c2-03e2-4771-9239-aba69f865565 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,931 | supabase-export-v2 | 36fd569da994cf15 | 'hello!'`` is an example of *tuple packing*: the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple. The reverse operation is also possible::
>>> x, y, z = t | trusted_official_docs | CPython Docs | 'hello!'`` is an example of *tuple packing*: the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple. The reverse operation is also possible::
>>> x, y, z = t | 'hello!'`` is an example of *tuple packing*: the values ``12345``, ``54321`` and ``'hello!'`` are packed together in a tuple. The reverse operation is also possible::
>>> x, y, z = t | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4b7e3b18-bba4-432d-9c85-24558fb0c718 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,917 | supabase-export-v2 | 6de3dcfe64f1582d | remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice). For example::
>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a[0]
>>> a
[1, 66.25, 333, 333, 1234.5]
>>> del a[2:4]
>>> a
[1, 66.25, 1234.5]
>>> del a[:]
>>> a
[] | trusted_official_docs | CPython Docs | remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice). For example::
>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a[0]
>>> a
[1, 66.25, 333, 333, 1234.5]
>>> del a[2:4]
>>> a
[1, 66.25, 1234.5]
>>> del a[:]
>>> a
[] | remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice). For example::
>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a[0]
>>> a
[1, 66.25, 333, 333, 1234.5]
>>> del a[2:4]
>>> a
[1, 66.25, 1234.5]
>>> del a[:]
>>> a
[] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4c3bd448-020a-4b1f-a3ae-9670e7f1eaf8 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,860 | supabase-export-v2 | 0639691a48b6eeed | >>> fruits ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape'] >>> fruits.sort() >>> fruits ['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear'] >>> fruits.pop() 'pear'
You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that
only modify the list have n... | trusted_official_docs | CPython Docs | >>> fruits ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape'] >>> fruits.sort() >>> fruits ['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear'] >>> fruits.pop() 'pear'
You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that
only modify the list have n... | >>> fruits ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', 'grape'] >>> fruits.sort() >>> fruits ['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear'] >>> fruits.pop() 'pear'
You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that
only modify the list have n... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4cb4d91d-7469-4b5c-aea3-44278cbf3508 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,910 | supabase-export-v2 | 2f8cc923f99707e7 | Unpacking can also be used in list comprehensions, as a way to build a new list representing the concatenation of an arbitrary number of iterables::
>>> x = [[1, 2, 3], [4, 5, 6], [], [7], [8, 9]]
>>> [*element for element in x]
[1, 2, 3, 4, 5, 6, 7, 8, 9] | trusted_official_docs | CPython Docs | Unpacking can also be used in list comprehensions, as a way to build a new list representing the concatenation of an arbitrary number of iterables::
>>> x = [[1, 2, 3], [4, 5, 6], [], [7], [8, 9]]
>>> [*element for element in x]
[1, 2, 3, 4, 5, 6, 7, 8, 9] | Unpacking can also be used in list comprehensions, as a way to build a new list representing the concatenation of an arbitrary number of iterables::
>>> x = [[1, 2, 3], [4, 5, 6], [], [7], [8, 9]]
>>> [*element for element in x]
[1, 2, 3, 4, 5, 6, 7, 8, 9] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4e375f1e-5d85-4aeb-887d-523eabb3f882 | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,861 | supabase-export-v2 | eaa6fbaa81c3fad8 | list have no return value printed -- they return the default ``None``. [#]_ This is a design principle for all mutable data structures in Python.
Another thing you might notice is that not all data can be sorted or
compared. For instance, ``[None, 'hello', 10]`` doesn't sort because
integers can't be compared to string... | trusted_official_docs | CPython Docs | list have no return value printed -- they return the default ``None``. [#]_ This is a design principle for all mutable data structures in Python.
Another thing you might notice is that not all data can be sorted or
compared. For instance, ``[None, 'hello', 10]`` doesn't sort because
integers can't be compared to string... | list have no return value printed -- they return the default ``None``. [#]_ This is a design principle for all mutable data structures in Python.
Another thing you might notice is that not all data can be sorted or
compared. For instance, ``[None, 'hello', 10]`` doesn't sort because
integers can't be compared to string... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4e55620f-7cb3-46ff-aaf7-1eeed203a62a | CPython Docs | file://datasets/cpython/Doc/tutorial/datastructures.rst | unknown | 5af9ff95-89a9-4ede-ba4d-c027dced5b35 | 53,987 | supabase-export-v2 | 50ff2fedbb7f3950 | .. _tut-comparing:
Comparing Sequences and Other Types
===================================
Sequence objects typically may be compared to other objects with the same sequence
type. The comparison uses *lexicographical* ordering: first the first two
items are compared, and if they differ this determines the outcome of th... | trusted_official_docs | CPython Docs | .. _tut-comparing:
Comparing Sequences and Other Types
===================================
Sequence objects typically may be compared to other objects with the same sequence
type. The comparison uses *lexicographical* ordering: first the first two
items are compared, and if they differ this determines the outcome of th... | .. _tut-comparing:
Comparing Sequences and Other Types
===================================
Sequence objects typically may be compared to other objects with the same sequence
type. The comparison uses *lexicographical* ordering: first the first two
items are compared, and if they differ this determines the outcome of th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.