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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4bd3e88c-5df6-4a2f-9217-821f80f82bec | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,851 | supabase-export-v2 | 1b31581aa68f0ee3 | arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method's instance object before the first argument.
In general, methods work as follows. When a non-data attribute
of an instance is referenced, the instance's class is searched. If the name denotes a va... | trusted_official_docs | CPython Docs | arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method's instance object before the first argument.
In general, methods work as follows. When a non-data attribute
of an instance is referenced, the instance's class is searched. If the name denotes a va... | arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method's instance object before the first argument.
In general, methods work as follows. When a non-data attribute
of an instance is referenced, the instance's class is searched. If the name denotes a va... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4c13e978-4896-411a-8847-3e9fc190b232 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,939 | supabase-export-v2 | 32f1d812ccbc2d66 | 0x10c90e650> >>> next(it) 'a' >>> next(it) 'b' >>> next(it) 'c' >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> next(it) StopIteration
Having seen the mechanics behind the iterator protocol, it is easy to add
iterator behavior to your classes. Define an :meth:`~container.__iter__` me... | trusted_official_docs | CPython Docs | 0x10c90e650> >>> next(it) 'a' >>> next(it) 'b' >>> next(it) 'c' >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> next(it) StopIteration
Having seen the mechanics behind the iterator protocol, it is easy to add
iterator behavior to your classes. Define an :meth:`~container.__iter__` me... | 0x10c90e650> >>> next(it) 'a' >>> next(it) 'b' >>> next(it) 'c' >>> next(it) Traceback (most recent call last): File "<stdin>", line 1, in <module> next(it) StopIteration
Having seen the mechanics behind the iterator protocol, it is easy to add
iterator behavior to your classes. Define an :meth:`~container.__iter__` me... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4d36c514-f010-479b-8fa9-5b9cca0e6a95 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,926 | supabase-export-v2 | d1a7afce252271b4 | Odds and Ends =============
Sometimes it is useful to have a data type similar to the Pascal "record" or C
"struct", bundling together a few named data items. The idiomatic approach
is to use :mod:`dataclasses` for this purpose:: | trusted_official_docs | CPython Docs | Odds and Ends =============
Sometimes it is useful to have a data type similar to the Pascal "record" or C
"struct", bundling together a few named data items. The idiomatic approach
is to use :mod:`dataclasses` for this purpose:: | Odds and Ends =============
Sometimes it is useful to have a data type similar to the Pascal "record" or C
"struct", bundling together a few named data items. The idiomatic approach
is to use :mod:`dataclasses` for this purpose:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4dcc82d4-0e16-41e4-8d23-1b9ff34d794f | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,922 | supabase-export-v2 | fde934e73cf78c62 | def update(self, keys, values): # provides new signature for update() # but does not break __init__() for item in zip(keys, values): self.items_list.append(item)
The above example would work even if ``MappingSubclass`` were to introduce a
``__update`` identifier since it is replaced with ``_Mapping__update`` in the
``M... | trusted_official_docs | CPython Docs | def update(self, keys, values): # provides new signature for update() # but does not break __init__() for item in zip(keys, values): self.items_list.append(item)
The above example would work even if ``MappingSubclass`` were to introduce a
``__update`` identifier since it is replaced with ``_Mapping__update`` in the
``M... | def update(self, keys, values): # provides new signature for update() # but does not break __init__() for item in zip(keys, values): self.items_list.append(item)
The above example would work even if ``MappingSubclass`` were to introduce a
``__update`` identifier since it is replaced with ``_Mapping__update`` in the
``M... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4e2ac23c-239b-4cec-8778-f66ecb54efc8 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,791 | supabase-export-v2 | 3a95b8e83a876000 | attempt to write to such a variable will simply create a *new* local variable in the innermost scope, leaving the identically named outer variable unchanged).
Usually, the local scope references the local names of the (textually) current
function. Outside functions, the local scope references the same namespace as
the ... | trusted_official_docs | CPython Docs | attempt to write to such a variable will simply create a *new* local variable in the innermost scope, leaving the identically named outer variable unchanged).
Usually, the local scope references the local names of the (textually) current
function. Outside functions, the local scope references the same namespace as
the ... | attempt to write to such a variable will simply create a *new* local variable in the innermost scope, leaving the identically named outer variable unchanged).
Usually, the local scope references the local names of the (textually) current
function. Outside functions, the local scope references the same namespace as
the ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4fa5424b-d928-4f02-9bd4-7462aad77629 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,849 | supabase-export-v2 | 5a16c3cff3e55ced | will continue to print ``hello world`` until the end of time.
What exactly happens when a method is called? You may have noticed that
``x.f()`` was called without an argument above, even though the function
definition for :meth:`!f` specified an argument. What happened to the argument? Surely Python raises an exception... | trusted_official_docs | CPython Docs | will continue to print ``hello world`` until the end of time.
What exactly happens when a method is called? You may have noticed that
``x.f()`` was called without an argument above, even though the function
definition for :meth:`!f` specified an argument. What happened to the argument? Surely Python raises an exception... | will continue to print ``hello world`` until the end of time.
What exactly happens when a method is called? You may have noticed that
``x.f()`` was called without an argument above, even though the function
definition for :meth:`!f` specified an argument. What happened to the argument? Surely Python raises an exception... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
53a7b64a-bb9e-4553-be0e-c27bb8b39b34 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,924 | supabase-export-v2 | c0da813f72ee4b38 | is possible to access or modify a variable that is considered private. This can even be useful in special circumstances, such as in the debugger.
Notice that code passed to ``exec()`` or ``eval()`` does not consider the
classname of the invoking class to be the current class; this is similar to the
effect of the ``glob... | trusted_official_docs | CPython Docs | is possible to access or modify a variable that is considered private. This can even be useful in special circumstances, such as in the debugger.
Notice that code passed to ``exec()`` or ``eval()`` does not consider the
classname of the invoking class to be the current class; this is similar to the
effect of the ``glob... | is possible to access or modify a variable that is considered private. This can even be useful in special circumstances, such as in the debugger.
Notice that code passed to ``exec()`` or ``eval()`` does not consider the
classname of the invoking class to be the current class; this is similar to the
effect of the ``glob... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5500cc9e-ed73-4939-ba1b-3bf691959a69 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,950 | supabase-export-v2 | 23f57d2fe6e27db6 | >>> for char in reverse('golf'): ... print(char) ... f l o g
Anything that can be done with generators can also be done with class-based
iterators as described in the previous section. What makes generators so
compact is that the :meth:`~iterator.__iter__` and :meth:`~generator.__next__` methods
are created automatical... | trusted_official_docs | CPython Docs | >>> for char in reverse('golf'): ... print(char) ... f l o g
Anything that can be done with generators can also be done with class-based
iterators as described in the previous section. What makes generators so
compact is that the :meth:`~iterator.__iter__` and :meth:`~generator.__next__` methods
are created automatical... | >>> for char in reverse('golf'): ... print(char) ... f l o g
Anything that can be done with generators can also be done with class-based
iterators as described in the previous section. What makes generators so
compact is that the :meth:`~iterator.__iter__` and :meth:`~generator.__next__` methods
are created automatical... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
552cde5e-ca09-4161-bbbd-f26743a4342e | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,873 | supabase-export-v2 | ba2704a808d55fcd | If the same attribute name occurs in both an instance and in a class, then attribute lookup prioritizes the instance::
>>> class Warehouse:
... purpose = 'storage'
... region = 'west'
... >>> w1 = Warehouse()
>>> print(w1.purpose, w1.region)
storage west
>>> w2 = Warehouse()
>>> w2.region = 'east'
>>> print(w2.... | trusted_official_docs | CPython Docs | If the same attribute name occurs in both an instance and in a class, then attribute lookup prioritizes the instance::
>>> class Warehouse:
... purpose = 'storage'
... region = 'west'
... >>> w1 = Warehouse()
>>> print(w1.purpose, w1.region)
storage west
>>> w2 = Warehouse()
>>> w2.region = 'east'
>>> print(w2.... | If the same attribute name occurs in both an instance and in a class, then attribute lookup prioritizes the instance::
>>> class Warehouse:
... purpose = 'storage'
... region = 'west'
... >>> w1 = Warehouse()
>>> print(w1.purpose, w1.region)
storage west
>>> w2 = Warehouse()
>>> w2.region = 'east'
>>> print(w2.... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5966b65c-2dca-4304-b600-78f66f45b903 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,821 | supabase-export-v2 | a60972351e885f45 | Class objects support two kinds of operations: attribute references and instantiation.
*Attribute references* use the standard syntax used for all attribute references
in Python: ``obj.name``. Valid attribute names are all the names that were in
the class's namespace when the class object was created. So, if the class
... | trusted_official_docs | CPython Docs | Class objects support two kinds of operations: attribute references and instantiation.
*Attribute references* use the standard syntax used for all attribute references
in Python: ``obj.name``. Valid attribute names are all the names that were in
the class's namespace when the class object was created. So, if the class
... | Class objects support two kinds of operations: attribute references and instantiation.
*Attribute references* use the standard syntax used for all attribute references
in Python: ``obj.name``. Valid attribute names are all the names that were in
the class's namespace when the class object was created. So, if the class
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5cb1e7e2-631f-46c7-a9d3-24dd7b6abb78 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,858 | supabase-export-v2 | 1f699df48f9908ab | def __init__(self, name): self.name = name # instance variable unique to each instance
>>> d = Dog('Fido')
>>> e = Dog('Buddy')
>>> d.kind # shared by all dogs
'canine'
>>> e.kind # shared by all dogs
'canine'
>>> d.name # unique to d
'Fido'
>>> e.name # unique to e
'Buddy' | trusted_official_docs | CPython Docs | def __init__(self, name): self.name = name # instance variable unique to each instance
>>> d = Dog('Fido')
>>> e = Dog('Buddy')
>>> d.kind # shared by all dogs
'canine'
>>> e.kind # shared by all dogs
'canine'
>>> d.name # unique to d
'Fido'
>>> e.name # unique to e
'Buddy' | def __init__(self, name): self.name = name # instance variable unique to each instance
>>> d = Dog('Fido')
>>> e = Dog('Buddy')
>>> d.kind # shared by all dogs
'canine'
>>> e.kind # shared by all dogs
'canine'
>>> d.name # unique to d
'Fido'
>>> e.name # unique to e
'Buddy' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
61103b37-2092-4657-8bf0-e54407c6811b | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,959 | supabase-export-v2 | 4bb362fa9ddd6d4b | >>> xvec = [10, 20, 30] >>> yvec = [7, 5, 3] >>> sum(x*y for x,y in zip(xvec, yvec)) # dot product 260
>>> unique_words = set(word for line in page for word in line.split()) | trusted_official_docs | CPython Docs | >>> xvec = [10, 20, 30] >>> yvec = [7, 5, 3] >>> sum(x*y for x,y in zip(xvec, yvec)) # dot product 260
>>> unique_words = set(word for line in page for word in line.split()) | >>> xvec = [10, 20, 30] >>> yvec = [7, 5, 3] >>> sum(x*y for x,y in zip(xvec, yvec)) # dot product 260
>>> unique_words = set(word for line in page for word in line.split()) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
62b6123b-b912-46c6-b596-08bb785fb10b | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,771 | supabase-export-v2 | 5934896c89b3a786 | ******* Classes *******
Classes provide a means of bundling data and functionality together. Creating
a new class creates a new *type* of object, allowing new *instances* of that
type to be made. Each class instance can have attributes attached to it for
maintaining its state. Class instances can also have methods (def... | trusted_official_docs | CPython Docs | ******* Classes *******
Classes provide a means of bundling data and functionality together. Creating
a new class creates a new *type* of object, allowing new *instances* of that
type to be made. Each class instance can have attributes attached to it for
maintaining its state. Class instances can also have methods (def... | ******* Classes *******
Classes provide a means of bundling data and functionality together. Creating
a new class creates a new *type* of object, allowing new *instances* of that
type to be made. Each class instance can have attributes attached to it for
maintaining its state. Class instances can also have methods (def... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
62d702d3-68c5-46c8-8ae2-e190d7e8f905 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,832 | supabase-export-v2 | 55a4f38dea18feb3 | x = MyClass()
Of course, the :meth:`~object.__init__` method may have arguments for greater
flexibility. In that case, arguments given to the class instantiation operator
are passed on to :meth:`!__init__`. For example, :: | trusted_official_docs | CPython Docs | x = MyClass()
Of course, the :meth:`~object.__init__` method may have arguments for greater
flexibility. In that case, arguments given to the class instantiation operator
are passed on to :meth:`!__init__`. For example, :: | x = MyClass()
Of course, the :meth:`~object.__init__` method may have arguments for greater
flexibility. In that case, arguments given to the class instantiation operator
are passed on to :meth:`!__init__`. For example, :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
67227d50-ea17-4e54-8dae-d01310181321 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,780 | supabase-export-v2 | 3289610c065002e9 | Python Scopes and Namespaces ============================
Before introducing classes, I first have to tell you something about Python's
scope rules. Class definitions play some neat tricks with namespaces, and you
need to know how scopes and namespaces work to fully understand what's going on. Incidentally, knowledge a... | trusted_official_docs | CPython Docs | Python Scopes and Namespaces ============================
Before introducing classes, I first have to tell you something about Python's
scope rules. Class definitions play some neat tricks with namespaces, and you
need to know how scopes and namespaces work to fully understand what's going on. Incidentally, knowledge a... | Python Scopes and Namespaces ============================
Before introducing classes, I first have to tell you something about Python's
scope rules. Class definitions play some neat tricks with namespaces, and you
need to know how scopes and namespaces work to fully understand what's going on. Incidentally, knowledge a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
68cdf2cc-3866-4a05-83fc-cee4964d19d7 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,788 | supabase-export-v2 | c49a43c2255c3ec8 | where a namespace is directly accessible. "Directly accessible" here means that an unqualified reference to a name attempts to find the name in the namespace.
Although scopes are determined statically, they are used dynamically. At any
time during execution, there are 3 or 4 nested scopes whose namespaces are
directly ... | trusted_official_docs | CPython Docs | where a namespace is directly accessible. "Directly accessible" here means that an unqualified reference to a name attempts to find the name in the namespace.
Although scopes are determined statically, they are used dynamically. At any
time during execution, there are 3 or 4 nested scopes whose namespaces are
directly ... | where a namespace is directly accessible. "Directly accessible" here means that an unqualified reference to a name attempts to find the name in the namespace.
Although scopes are determined statically, they are used dynamically. At any
time during execution, there are 3 or 4 nested scopes whose namespaces are
directly ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
68fd8d14-9a74-4444-b446-001af90e1da9 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,784 | supabase-export-v2 | 2dab1d7542f10006 | there happens to be a straightforward mapping between the module's attributes and the global names defined in the module: they share the same namespace! [#]_
Attributes may be read-only or writable. In the latter case, assignment to
attributes is possible. Module attributes are writable: you can write
``modname.the_ans... | trusted_official_docs | CPython Docs | there happens to be a straightforward mapping between the module's attributes and the global names defined in the module: they share the same namespace! [#]_
Attributes may be read-only or writable. In the latter case, assignment to
attributes is possible. Module attributes are writable: you can write
``modname.the_ans... | there happens to be a straightforward mapping between the module's attributes and the global names defined in the module: they share the same namespace! [#]_
Attributes may be read-only or writable. In the latter case, assignment to
attributes is possible. Module attributes are writable: you can write
``modname.the_ans... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
767b6dc4-5ae2-4220-b696-a5b4777befcf | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,818 | supabase-export-v2 | a1bf5df067b7466c | scope --- thus, all assignments to local variables go into this new namespace. In particular, function definitions bind the name of the new function here.
When a class definition is left normally (via the end), a *class object* is
created. This is basically a wrapper around the contents of the namespace
created by the ... | trusted_official_docs | CPython Docs | scope --- thus, all assignments to local variables go into this new namespace. In particular, function definitions bind the name of the new function here.
When a class definition is left normally (via the end), a *class object* is
created. This is basically a wrapper around the contents of the namespace
created by the ... | scope --- thus, all assignments to local variables go into this new namespace. In particular, function definitions bind the name of the new function here.
When a class definition is left normally (via the end), a *class object* is
created. This is basically a wrapper around the contents of the namespace
created by the ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
776da6b7-b488-47ea-bdec-a62b579b2eaa | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,905 | supabase-export-v2 | 15510ee58e629f44 | class DerivedClassName(Base1, Base2, Base3): <statement-1> . . . <statement-N>
For most purposes, in the simplest cases, you can think of the search for
attributes inherited from a parent class as depth-first, left-to-right, not
searching twice in the same class where there is an overlap in the hierarchy. Thus, if an a... | trusted_official_docs | CPython Docs | class DerivedClassName(Base1, Base2, Base3): <statement-1> . . . <statement-N>
For most purposes, in the simplest cases, you can think of the search for
attributes inherited from a parent class as depth-first, left-to-right, not
searching twice in the same class where there is an overlap in the hierarchy. Thus, if an a... | class DerivedClassName(Base1, Base2, Base3): <statement-1> . . . <statement-N>
For most purposes, in the simplest cases, you can think of the search for
attributes inherited from a parent class as depth-first, left-to-right, not
searching twice in the same class where there is an overlap in the hierarchy. Thus, if an a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77e3f030-592e-41cf-9241-debf4641215f | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,900 | supabase-export-v2 | 1b56739760c58d30 | * Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)`` will be ``True`` only if ``obj.__class__`` is :class:`int` or some class derived from :class:`int`.
* Use :func:`issubclass` to check class inheritance: ``issubclass(bool, int)``
is ``True`` since :class:`bool` is a subclass of :class:`int`... | trusted_official_docs | CPython Docs | * Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)`` will be ``True`` only if ``obj.__class__`` is :class:`int` or some class derived from :class:`int`.
* Use :func:`issubclass` to check class inheritance: ``issubclass(bool, int)``
is ``True`` since :class:`bool` is a subclass of :class:`int`... | * Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)`` will be ``True`` only if ``obj.__class__`` is :class:`int` or some class derived from :class:`int`.
* Use :func:`issubclass` to check class inheritance: ``issubclass(bool, int)``
is ``True`` since :class:`bool` is a subclass of :class:`int`... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7849b47b-d45c-411f-acef-21d3276d073f | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,933 | supabase-export-v2 | 5e31b8b48a8ce9df | such as sequence subscripting or arithmetic operators, and assigning such a "pseudo-file" to sys.stdin will not cause the interpreter to read further input from it.)
:ref:`Instance method objects <instance-methods>` have attributes, too:
:attr:`m.__self__ <method.__self__>` is the instance
object with the method :meth:... | trusted_official_docs | CPython Docs | such as sequence subscripting or arithmetic operators, and assigning such a "pseudo-file" to sys.stdin will not cause the interpreter to read further input from it.)
:ref:`Instance method objects <instance-methods>` have attributes, too:
:attr:`m.__self__ <method.__self__>` is the instance
object with the method :meth:... | such as sequence subscripting or arithmetic operators, and assigning such a "pseudo-file" to sys.stdin will not cause the interpreter to read further input from it.)
:ref:`Instance method objects <instance-methods>` have attributes, too:
:attr:`m.__self__ <method.__self__>` is the instance
object with the method :meth:... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
814d536b-155e-441d-b214-a63989ff0bc4 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,837 | supabase-export-v2 | 5fac00d9fbd31247 | with instance objects? The only operations understood by instance objects are attribute references. There are two kinds of valid attribute names: data attributes and methods.
*Data attributes* correspond to "instance variables" in Smalltalk, and to "data
members" in C++. Data attributes need not be declared; like local... | trusted_official_docs | CPython Docs | with instance objects? The only operations understood by instance objects are attribute references. There are two kinds of valid attribute names: data attributes and methods.
*Data attributes* correspond to "instance variables" in Smalltalk, and to "data
members" in C++. Data attributes need not be declared; like local... | with instance objects? The only operations understood by instance objects are attribute references. There are two kinds of valid attribute names: data attributes and methods.
*Data attributes* correspond to "instance variables" in Smalltalk, and to "data
members" in C++. Data attributes need not be declared; like local... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
82397253-3e3b-4283-a743-d07b4d0834e8 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,816 | supabase-export-v2 | 91a5f80f6d62741d | be executed before they have any effect. (You could conceivably place a class definition in a branch of an :keyword:`if` statement, or inside a function.)
In practice, the statements inside a class definition will usually be function
definitions, but other statements are allowed, and sometimes useful --- we'll
come bac... | trusted_official_docs | CPython Docs | be executed before they have any effect. (You could conceivably place a class definition in a branch of an :keyword:`if` statement, or inside a function.)
In practice, the statements inside a class definition will usually be function
definitions, but other statements are allowed, and sometimes useful --- we'll
come bac... | be executed before they have any effect. (You could conceivably place a class definition in a branch of an :keyword:`if` statement, or inside a function.)
In practice, the statements inside a class definition will usually be function
definitions, but other statements are allowed, and sometimes useful --- we'll
come bac... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
88668d49-3c62-470f-9e58-9acf77753854 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,899 | supabase-export-v2 | 20f0877ca918e5e2 | Python has two built-in functions that work with inheritance:
* Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)``
will be ``True`` only if ``obj.__class__`` is :class:`int` or some class
derived from :class:`int`. | trusted_official_docs | CPython Docs | Python has two built-in functions that work with inheritance:
* Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)``
will be ``True`` only if ``obj.__class__`` is :class:`int` or some class
derived from :class:`int`. | Python has two built-in functions that work with inheritance:
* Use :func:`isinstance` to check an instance's type: ``isinstance(obj, int)``
will be ``True`` only if ``obj.__class__`` is :class:`int` or some class
derived from :class:`int`. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
895ffb7c-8b8f-47c3-98c5-03e03b56a756 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,839 | supabase-export-v2 | d8f70ecd783793bd | x.counter = 1 while x.counter < 10: x.counter = x.counter * 2 print(x.counter) del x.counter
The other kind of instance attribute reference is a *method*. A method is a
function that "belongs to" an object. | trusted_official_docs | CPython Docs | x.counter = 1 while x.counter < 10: x.counter = x.counter * 2 print(x.counter) del x.counter
The other kind of instance attribute reference is a *method*. A method is a
function that "belongs to" an object. | x.counter = 1 while x.counter < 10: x.counter = x.counter * 2 print(x.counter) del x.counter
The other kind of instance attribute reference is a *method*. A method is a
function that "belongs to" an object. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8dad7d49-925b-4d34-983b-a5925fbf9edb | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,774 | supabase-export-v2 | cadf1ac27197f186 | for extension by the user. Also, like in C++, most built-in operators with special syntax (arithmetic operators, subscripting etc.) can be redefined for class instances.
(Lacking universally accepted terminology to talk about classes, I will make
occasional use of Smalltalk and C++ terms. I would use Modula-3 terms, si... | trusted_official_docs | CPython Docs | for extension by the user. Also, like in C++, most built-in operators with special syntax (arithmetic operators, subscripting etc.) can be redefined for class instances.
(Lacking universally accepted terminology to talk about classes, I will make
occasional use of Smalltalk and C++ terms. I would use Modula-3 terms, si... | for extension by the user. Also, like in C++, most built-in operators with special syntax (arithmetic operators, subscripting etc.) can be redefined for class instances.
(Lacking universally accepted terminology to talk about classes, I will make
occasional use of Smalltalk and C++ terms. I would use Modula-3 terms, si... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
915963e0-9960-4f2b-a7f1-b4f654f6734f | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,854 | supabase-export-v2 | c8e6a929e8a039b9 | Class and Instance Variables ----------------------------
Generally speaking, instance variables are for data unique to each instance
and class variables are for attributes and methods shared by all instances
of the class:: | trusted_official_docs | CPython Docs | Class and Instance Variables ----------------------------
Generally speaking, instance variables are for data unique to each instance
and class variables are for attributes and methods shared by all instances
of the class:: | Class and Instance Variables ----------------------------
Generally speaking, instance variables are for data unique to each instance
and class variables are for attributes and methods shared by all instances
of the class:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
918ca08f-3adf-41c1-8811-6d2d22dd7e3e | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,830 | supabase-export-v2 | a5619188d09b58f5 | def __init__(self): self.data = []
When a class defines an :meth:`~object.__init__` method, class instantiation
automatically invokes :meth:`!__init__` for the newly created class instance. So
in this example, a new, initialized instance can be obtained by:: | trusted_official_docs | CPython Docs | def __init__(self): self.data = []
When a class defines an :meth:`~object.__init__` method, class instantiation
automatically invokes :meth:`!__init__` for the newly created class instance. So
in this example, a new, initialized instance can be obtained by:: | def __init__(self): self.data = []
When a class defines an :meth:`~object.__init__` method, class instantiation
automatically invokes :meth:`!__init__` for the newly created class instance. So
in this example, a new, initialized instance can be obtained by:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
96bf791f-055b-4e07-896e-1f9d5075f84e | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,888 | supabase-export-v2 | 895ec8b45eb91e38 | defined in this global scope, and in the next section we'll find some good reasons why a method would want to reference its own class.
Each value is an object, and therefore has a *class* (also called its *type*). It is stored as ``object.__class__``. | trusted_official_docs | CPython Docs | defined in this global scope, and in the next section we'll find some good reasons why a method would want to reference its own class.
Each value is an object, and therefore has a *class* (also called its *type*). It is stored as ``object.__class__``. | defined in this global scope, and in the next section we'll find some good reasons why a method would want to reference its own class.
Each value is an object, and therefore has a *class* (also called its *type*). It is stored as ``object.__class__``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
97995510-da30-4ce7-8c81-896a15f9fa24 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,783 | supabase-export-v2 | 383e9c7b62957a14 | for instance, two different modules may both define a function ``maximize`` without confusion --- users of the modules must prefix it with the module name.
By the way, I use the word *attribute* for any name following a dot --- for
example, in the expression ``z.real``, ``real`` is an attribute of the object
``z``. Str... | trusted_official_docs | CPython Docs | for instance, two different modules may both define a function ``maximize`` without confusion --- users of the modules must prefix it with the module name.
By the way, I use the word *attribute* for any name following a dot --- for
example, in the expression ``z.real``, ``real`` is an attribute of the object
``z``. Str... | for instance, two different modules may both define a function ``maximize`` without confusion --- users of the modules must prefix it with the module name.
By the way, I use the word *attribute* for any name following a dot --- for
example, in the expression ``z.real``, ``real`` is an attribute of the object
``z``. Str... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
989ab4dc-6b33-47b6-ba7d-bae43b67d123 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,923 | supabase-export-v2 | d9fb725e8a968540 | if ``MappingSubclass`` were to introduce a ``__update`` identifier since it is replaced with ``_Mapping__update`` in the ``Mapping`` class and ``_MappingSubclass__update`` in the ``MappingSubclass`` class respectively.
Note that the mangling rules are designed mostly to avoid accidents; it still is
possible to access o... | trusted_official_docs | CPython Docs | if ``MappingSubclass`` were to introduce a ``__update`` identifier since it is replaced with ``_Mapping__update`` in the ``Mapping`` class and ``_MappingSubclass__update`` in the ``MappingSubclass`` class respectively.
Note that the mangling rules are designed mostly to avoid accidents; it still is
possible to access o... | if ``MappingSubclass`` were to introduce a ``__update`` identifier since it is replaced with ``_Mapping__update`` in the ``Mapping`` class and ``_MappingSubclass__update`` in the ``MappingSubclass`` class respectively.
Note that the mangling rules are designed mostly to avoid accidents; it still is
possible to access o... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
997ea6fe-9195-4b16-96cb-a4dd7c4c5344 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,931 | supabase-export-v2 | 94591d325804962d | >>> john = Employee('john', 'computer lab', 1000) >>> john.dept 'computer lab' >>> john.salary 1000
A piece of Python code that expects a particular abstract data type can often be
passed a class that emulates the methods of that data type instead. For
instance, if you have a function that formats some data from a file... | trusted_official_docs | CPython Docs | >>> john = Employee('john', 'computer lab', 1000) >>> john.dept 'computer lab' >>> john.salary 1000
A piece of Python code that expects a particular abstract data type can often be
passed a class that emulates the methods of that data type instead. For
instance, if you have a function that formats some data from a file... | >>> john = Employee('john', 'computer lab', 1000) >>> john.dept 'computer lab' >>> john.salary 1000
A piece of Python code that expects a particular abstract data type can often be
passed a class that emulates the methods of that data type instead. For
instance, if you have a function that formats some data from a file... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
99efddcd-e8d6-4b86-ba55-41660d0a9258 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,865 | supabase-export-v2 | 836e61aaea9f84a0 | d = Dog('Fido') >>> e = Dog('Buddy') >>> d.add_trick('roll over') >>> e.add_trick('play dead') >>> d.tricks # unexpectedly shared by all dogs ['roll over', 'play dead']
Correct design of the class should use an instance variable instead:: | trusted_official_docs | CPython Docs | d = Dog('Fido') >>> e = Dog('Buddy') >>> d.add_trick('roll over') >>> e.add_trick('play dead') >>> d.tricks # unexpectedly shared by all dogs ['roll over', 'play dead']
Correct design of the class should use an instance variable instead:: | d = Dog('Fido') >>> e = Dog('Buddy') >>> d.add_trick('roll over') >>> e.add_trick('play dead') >>> d.tricks # unexpectedly shared by all dogs ['roll over', 'play dead']
Correct design of the class should use an instance variable instead:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9c738f67-aa8f-4ef7-a69c-0786dbedc92d | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,790 | supabase-export-v2 | 1c9dc8022eb6ee4e | also non-global names * the next-to-last scope contains the current module's global names * the outermost scope (searched last) is the namespace containing built-in names
If a name is declared global, then all references and assignments go directly to
the next-to-last scope containing the module's global names. To rebi... | trusted_official_docs | CPython Docs | also non-global names * the next-to-last scope contains the current module's global names * the outermost scope (searched last) is the namespace containing built-in names
If a name is declared global, then all references and assignments go directly to
the next-to-last scope containing the module's global names. To rebi... | also non-global names * the next-to-last scope contains the current module's global names * the outermost scope (searched last) is the namespace containing built-in names
If a name is declared global, then all references and assignments go directly to
the next-to-last scope containing the module's global names. To rebi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9f69f52e-ae8e-4ff3-a3e6-42a374994733 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,876 | supabase-export-v2 | 7f37469a001eabf0 | affecting the validity of the methods, as long as name conflicts are avoided --- again, a naming convention can save a lot of headaches here.
There is no shorthand for referencing data attributes (or other methods!) from
within methods. I find that this actually increases the readability of methods:
there is no chance ... | trusted_official_docs | CPython Docs | affecting the validity of the methods, as long as name conflicts are avoided --- again, a naming convention can save a lot of headaches here.
There is no shorthand for referencing data attributes (or other methods!) from
within methods. I find that this actually increases the readability of methods:
there is no chance ... | affecting the validity of the methods, as long as name conflicts are avoided --- again, a naming convention can save a lot of headaches here.
There is no shorthand for referencing data attributes (or other methods!) from
within methods. I find that this actually increases the readability of methods:
there is no chance ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a1beaa4a-9a91-43f8-854d-823e87baf133 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,906 | supabase-export-v2 | 39be06a0d94a7fda | :class:`!Base1`, then (recursively) in the base classes of :class:`!Base1`, and if it was not found there, it was searched for in :class:`!Base2`, and so on.
In fact, it is slightly more complex than that; the method resolution order
changes dynamically to support cooperative calls to :func:`super`. This
approach is kn... | trusted_official_docs | CPython Docs | :class:`!Base1`, then (recursively) in the base classes of :class:`!Base1`, and if it was not found there, it was searched for in :class:`!Base2`, and so on.
In fact, it is slightly more complex than that; the method resolution order
changes dynamically to support cooperative calls to :func:`super`. This
approach is kn... | :class:`!Base1`, then (recursively) in the base classes of :class:`!Base1`, and if it was not found there, it was searched for in :class:`!Base2`, and so on.
In fact, it is slightly more complex than that; the method resolution order
changes dynamically to support cooperative calls to :func:`super`. This
approach is kn... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a21ff185-ad50-4f81-b450-b2af76c368ce | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,850 | supabase-export-v2 | 6cd29f60a7f0942e | argument? Surely Python raises an exception when a function that requires an argument is called without any --- even if the argument isn't actually used...
Actually, you may have guessed the answer: the special thing about methods is
that the instance object is passed as the first argument of the function. In our
examp... | trusted_official_docs | CPython Docs | argument? Surely Python raises an exception when a function that requires an argument is called without any --- even if the argument isn't actually used...
Actually, you may have guessed the answer: the special thing about methods is
that the instance object is passed as the first argument of the function. In our
examp... | argument? Surely Python raises an exception when a function that requires an argument is called without any --- even if the argument isn't actually used...
Actually, you may have guessed the answer: the special thing about methods is
that the instance object is passed as the first argument of the function. In our
examp... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a4c9c54a-6353-44d5-915a-12576f815791 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,777 | supabase-export-v2 | 9a8c8e28c4786c6d | A Word About Names and Objects ==============================
Objects have individuality, and multiple names (in multiple scopes) can be bound
to the same object. This is known as aliasing in other languages. This is
usually not appreciated on a first glance at Python, and can be safely ignored
when dealing with immuta... | trusted_official_docs | CPython Docs | A Word About Names and Objects ==============================
Objects have individuality, and multiple names (in multiple scopes) can be bound
to the same object. This is known as aliasing in other languages. This is
usually not appreciated on a first glance at Python, and can be safely ignored
when dealing with immuta... | A Word About Names and Objects ==============================
Objects have individuality, and multiple names (in multiple scopes) can be bound
to the same object. This is known as aliasing in other languages. This is
usually not appreciated on a first glance at Python, and can be safely ignored
when dealing with immuta... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
abbb7751-f5a2-4568-8dfb-499d35114b7e | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,879 | supabase-export-v2 | 0f4915118b194f14 | function definition is textually enclosed in the class definition: assigning a function object to a local variable in the class is also ok. For example::
# Function defined outside the class
def f1(self, x, y):
return min(x, x+y) | trusted_official_docs | CPython Docs | function definition is textually enclosed in the class definition: assigning a function object to a local variable in the class is also ok. For example::
# Function defined outside the class
def f1(self, x, y):
return min(x, x+y) | function definition is textually enclosed in the class definition: assigning a function object to a local variable in the class is also ok. For example::
# Function defined outside the class
def f1(self, x, y):
return min(x, x+y) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ad93a95f-077b-416c-aaa2-5cf45962cbc3 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,894 | supabase-export-v2 | 33957a92c3608366 | class DerivedClassName(modname.BaseClassName):
Execution of a derived class definition proceeds the same as for a base class. When the class object is constructed, the base class is remembered. This is
used for resolving attribute references: if a requested attribute is not found
in the class, the search proceeds to lo... | trusted_official_docs | CPython Docs | class DerivedClassName(modname.BaseClassName):
Execution of a derived class definition proceeds the same as for a base class. When the class object is constructed, the base class is remembered. This is
used for resolving attribute references: if a requested attribute is not found
in the class, the search proceeds to lo... | class DerivedClassName(modname.BaseClassName):
Execution of a derived class definition proceeds the same as for a base class. When the class object is constructed, the base class is remembered. This is
used for resolving attribute references: if a requested attribute is not found
in the class, the search proceeds to lo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b26786a2-9853-4f13-9d09-960443f8e47d | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,911 | supabase-export-v2 | bc412d7a561b20d7 | Private Variables =================
"Private" instance variables that cannot be accessed except from inside an
object don't exist in Python. However, there is a convention that is followed
by most Python code: a name prefixed with an underscore (e.g. ``_spam``) should
be treated as a non-public part of the API (whether... | trusted_official_docs | CPython Docs | Private Variables =================
"Private" instance variables that cannot be accessed except from inside an
object don't exist in Python. However, there is a convention that is followed
by most Python code: a name prefixed with an underscore (e.g. ``_spam``) should
be treated as a non-public part of the API (whether... | Private Variables =================
"Private" instance variables that cannot be accessed except from inside an
object don't exist in Python. However, there is a convention that is followed
by most Python code: a name prefixed with an underscore (e.g. ``_spam``) should
be treated as a non-public part of the API (whether... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b40c0673-cf80-422c-a8c9-4dbfbf99cd86 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,951 | supabase-export-v2 | 7ff0af83906aefbd | done with class-based iterators as described in the previous section. What makes generators so compact is that the :meth:`~iterator.__iter__` and :meth:`~generator.__next__` methods are created automatically.
Another key feature is that the local variables and execution state are
automatically saved between calls. This... | trusted_official_docs | CPython Docs | done with class-based iterators as described in the previous section. What makes generators so compact is that the :meth:`~iterator.__iter__` and :meth:`~generator.__next__` methods are created automatically.
Another key feature is that the local variables and execution state are
automatically saved between calls. This... | done with class-based iterators as described in the previous section. What makes generators so compact is that the :meth:`~iterator.__iter__` and :meth:`~generator.__next__` methods are created automatically.
Another key feature is that the local variables and execution state are
automatically saved between calls. This... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b7300905-6473-4b5b-9969-cd5d7bda7f17 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,958 | supabase-export-v2 | b9bcb221175bd166 | >>> sum(i*i for i in range(10)) # sum of squares 285
>>> xvec = [10, 20, 30]
>>> yvec = [7, 5, 3]
>>> sum(x*y for x,y in zip(xvec, yvec)) # dot product
260 | trusted_official_docs | CPython Docs | >>> sum(i*i for i in range(10)) # sum of squares 285
>>> xvec = [10, 20, 30]
>>> yvec = [7, 5, 3]
>>> sum(x*y for x,y in zip(xvec, yvec)) # dot product
260 | >>> sum(i*i for i in range(10)) # sum of squares 285
>>> xvec = [10, 20, 30]
>>> yvec = [7, 5, 3]
>>> sum(x*y for x,y in zip(xvec, yvec)) # dot product
260 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b8431492-4ed2-4a37-bce6-bd42eec16fd6 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,782 | supabase-export-v2 | 24fa74b13dd2b47a | Let's begin with some definitions.
A *namespace* is a mapping from names to objects. Most namespaces are currently
implemented as Python dictionaries, but that's normally not noticeable in any
way (except for performance), and it may change in the future. Examples of
namespaces are: the set of built-in names (containin... | trusted_official_docs | CPython Docs | Let's begin with some definitions.
A *namespace* is a mapping from names to objects. Most namespaces are currently
implemented as Python dictionaries, but that's normally not noticeable in any
way (except for performance), and it may change in the future. Examples of
namespaces are: the set of built-in names (containin... | Let's begin with some definitions.
A *namespace* is a mapping from names to objects. Most namespaces are currently
implemented as Python dictionaries, but that's normally not noticeable in any
way (except for performance), and it may change in the future. Examples of
namespaces are: the set of built-in names (containin... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b92c0a09-539b-43e0-9125-df5ab4fdd405 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,877 | supabase-export-v2 | e31318e92223f716 | find that this actually increases the readability of methods: there is no chance of confusing local variables and instance variables when glancing through a method.
Often, the first argument of a method is called ``self``. This is nothing more
than a convention: the name ``self`` has absolutely no special meaning to
Py... | trusted_official_docs | CPython Docs | find that this actually increases the readability of methods: there is no chance of confusing local variables and instance variables when glancing through a method.
Often, the first argument of a method is called ``self``. This is nothing more
than a convention: the name ``self`` has absolutely no special meaning to
Py... | find that this actually increases the readability of methods: there is no chance of confusing local variables and instance variables when glancing through a method.
Often, the first argument of a method is called ``self``. This is nothing more
than a convention: the name ``self`` has absolutely no special meaning to
Py... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bb90e290-4aea-4c0b-9d0d-c3f1c6d8e08e | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,912 | supabase-export-v2 | f0d9537be129a0ad | API (whether it is a function, a method or a data member). It should be considered an implementation detail and subject to change without notice.
.. index::
pair: name; mangling | trusted_official_docs | CPython Docs | API (whether it is a function, a method or a data member). It should be considered an implementation detail and subject to change without notice.
.. index::
pair: name; mangling | API (whether it is a function, a method or a data member). It should be considered an implementation detail and subject to change without notice.
.. index::
pair: name; mangling | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bc59b4bc-24f5-4dd4-a424-ad58a40c1df9 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,955 | supabase-export-v2 | dfea29904da4978e | Generator Expressions =====================
Some simple generators can be coded succinctly as expressions using a syntax
similar to list comprehensions but with parentheses instead of square brackets. These expressions are designed for situations where the generator is used right
away by an enclosing function. Generato... | trusted_official_docs | CPython Docs | Generator Expressions =====================
Some simple generators can be coded succinctly as expressions using a syntax
similar to list comprehensions but with parentheses instead of square brackets. These expressions are designed for situations where the generator is used right
away by an enclosing function. Generato... | Generator Expressions =====================
Some simple generators can be coded succinctly as expressions using a syntax
similar to list comprehensions but with parentheses instead of square brackets. These expressions are designed for situations where the generator is used right
away by an enclosing function. Generato... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
be840937-a813-4731-905c-67b5b4554752 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,968 | supabase-export-v2 | 9c1701353bde22c1 | .. rubric:: Footnotes
.. [#] Except for one thing. Module objects have a secret read-only attribute called
:attr:`~object.__dict__` which returns the dictionary used to implement the module's
namespace; the name ``__dict__`` is an attribute but not a global name. Obviously, using this violates the abstraction of name... | trusted_official_docs | CPython Docs | .. rubric:: Footnotes
.. [#] Except for one thing. Module objects have a secret read-only attribute called
:attr:`~object.__dict__` which returns the dictionary used to implement the module's
namespace; the name ``__dict__`` is an attribute but not a global name. Obviously, using this violates the abstraction of name... | .. rubric:: Footnotes
.. [#] Except for one thing. Module objects have a secret read-only attribute called
:attr:`~object.__dict__` which returns the dictionary used to implement the module's
namespace; the name ``__dict__`` is an attribute but not a global name. Obviously, using this violates the abstraction of name... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c0d06bfc-eade-421e-867e-550082cadc1f | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,772 | supabase-export-v2 | de3c271eec038f44 | instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state.
Compared with other programming languages, Python's class mechanism adds classes
with a minimum of new syntax and semantics. It is a mixture of the class
mechanism... | trusted_official_docs | CPython Docs | instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state.
Compared with other programming languages, Python's class mechanism adds classes
with a minimum of new syntax and semantics. It is a mixture of the class
mechanism... | instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state.
Compared with other programming languages, Python's class mechanism adds classes
with a minimum of new syntax and semantics. It is a mixture of the class
mechanism... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c1e5027f-7a35-4310-bc7a-d243ded2cf69 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,822 | supabase-export-v2 | 9daa504d7c4f1d36 | names are all the names that were in the class's namespace when the class object was created. So, if the class definition looked like this::
class MyClass:
"""A simple example class"""
i = 12345 | trusted_official_docs | CPython Docs | names are all the names that were in the class's namespace when the class object was created. So, if the class definition looked like this::
class MyClass:
"""A simple example class"""
i = 12345 | names are all the names that were in the class's namespace when the class object was created. So, if the class definition looked like this::
class MyClass:
"""A simple example class"""
i = 12345 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c60a30b8-9c9e-42ec-bd77-8f3a239d85fd | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,891 | supabase-export-v2 | 8f9c9ddd93dc20ea | course, a language feature would not be worthy of the name "class" without supporting inheritance. The syntax for a derived class definition looks like this::
class DerivedClassName(BaseClassName):
<statement-1>
. . . <statement-N> | trusted_official_docs | CPython Docs | course, a language feature would not be worthy of the name "class" without supporting inheritance. The syntax for a derived class definition looks like this::
class DerivedClassName(BaseClassName):
<statement-1>
. . . <statement-N> | course, a language feature would not be worthy of the name "class" without supporting inheritance. The syntax for a derived class definition looks like this::
class DerivedClassName(BaseClassName):
<statement-1>
. . . <statement-N> | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c6b42a95-d2e1-4bc3-84a3-aa242201887a | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,946 | supabase-export-v2 | e8dbf5e0f373187d | Generators ==========
:term:`Generators <generator>` are a simple and powerful tool for creating iterators. They
are written like regular functions but use the :keyword:`yield` statement
whenever they want to return data. Each time :func:`next` is called on it, the
generator resumes where it left off (it remembers all ... | trusted_official_docs | CPython Docs | Generators ==========
:term:`Generators <generator>` are a simple and powerful tool for creating iterators. They
are written like regular functions but use the :keyword:`yield` statement
whenever they want to return data. Each time :func:`next` is called on it, the
generator resumes where it left off (it remembers all ... | Generators ==========
:term:`Generators <generator>` are a simple and powerful tool for creating iterators. They
are written like regular functions but use the :keyword:`yield` statement
whenever they want to return data. Each time :func:`next` is called on it, the
generator resumes where it left off (it remembers all ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c6f22ec1-b2da-4164-8033-ed6179d033ab | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,829 | supabase-export-v2 | f9fc2a14ae7bb74b | classes like to create objects with instances customized to a specific initial state. Therefore a class may define a special method named :meth:`~object.__init__`, like this::
def __init__(self):
self.data = [] | trusted_official_docs | CPython Docs | classes like to create objects with instances customized to a specific initial state. Therefore a class may define a special method named :meth:`~object.__init__`, like this::
def __init__(self):
self.data = [] | classes like to create objects with instances customized to a specific initial state. Therefore a class may define a special method named :meth:`~object.__init__`, like this::
def __init__(self):
self.data = [] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c9c99564-6b51-4988-a558-f94b64896e9f | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,892 | supabase-export-v2 | 5f6f507fa0645ae3 | class DerivedClassName(BaseClassName): <statement-1> . . . <statement-N>
The name :class:`!BaseClassName` must be defined in a
namespace accessible from the scope containing the
derived class definition. In place of a base class name, other arbitrary
expressions are also allowed. This can be useful, for example, when t... | trusted_official_docs | CPython Docs | class DerivedClassName(BaseClassName): <statement-1> . . . <statement-N>
The name :class:`!BaseClassName` must be defined in a
namespace accessible from the scope containing the
derived class definition. In place of a base class name, other arbitrary
expressions are also allowed. This can be useful, for example, when t... | class DerivedClassName(BaseClassName): <statement-1> . . . <statement-N>
The name :class:`!BaseClassName` must be defined in a
namespace accessible from the scope containing the
derived class definition. In place of a base class name, other arbitrary
expressions are also allowed. This can be useful, for example, when t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ca914b0f-298e-4fe3-97ac-1cbecb0b1694 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,878 | supabase-export-v2 | 9ec4821469fe0177 | less readable to other Python programmers, and it is also conceivable that a *class browser* program might be written that relies upon such a convention.
Any function object that is a class attribute defines a method for instances of
that class. It is not necessary that the function definition is textually
enclosed in ... | trusted_official_docs | CPython Docs | less readable to other Python programmers, and it is also conceivable that a *class browser* program might be written that relies upon such a convention.
Any function object that is a class attribute defines a method for instances of
that class. It is not necessary that the function definition is textually
enclosed in ... | less readable to other Python programmers, and it is also conceivable that a *class browser* program might be written that relies upon such a convention.
Any function object that is a class attribute defines a method for instances of
that class. It is not necessary that the function definition is textually
enclosed in ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ccc2ab89-e3a9-4ddf-85eb-843e1a1922f6 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,833 | supabase-export-v2 | 5f93e860963bd5e2 | method may have arguments for greater flexibility. In that case, arguments given to the class instantiation operator are passed on to :meth:`!__init__`. For example, ::
>>> class Complex:
... def __init__(self, realpart, imagpart):
... self.r = realpart
... self.i = imagpart
... >>> x = Complex(3.0, -4.5)
>>> x.r,... | trusted_official_docs | CPython Docs | method may have arguments for greater flexibility. In that case, arguments given to the class instantiation operator are passed on to :meth:`!__init__`. For example, ::
>>> class Complex:
... def __init__(self, realpart, imagpart):
... self.r = realpart
... self.i = imagpart
... >>> x = Complex(3.0, -4.5)
>>> x.r,... | method may have arguments for greater flexibility. In that case, arguments given to the class instantiation operator are passed on to :meth:`!__init__`. For example, ::
>>> class Complex:
... def __init__(self, realpart, imagpart):
... self.r = realpart
... self.i = imagpart
... >>> x = Complex(3.0, -4.5)
>>> x.r,... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cce91d56-76bb-4929-87bc-e9423a9c7ebc | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,787 | supabase-export-v2 | 2decd82116f9f5e1 | within the function. (Actually, forgetting would be a better way to describe what actually happens.) Of course, recursive invocations each have their own local namespace.
A *scope* is a textual region of a Python program where a namespace is directly
accessible. "Directly accessible" here means that an unqualified refe... | trusted_official_docs | CPython Docs | within the function. (Actually, forgetting would be a better way to describe what actually happens.) Of course, recursive invocations each have their own local namespace.
A *scope* is a textual region of a Python program where a namespace is directly
accessible. "Directly accessible" here means that an unqualified refe... | within the function. (Actually, forgetting would be a better way to describe what actually happens.) Of course, recursive invocations each have their own local namespace.
A *scope* is a textual region of a Python program where a namespace is directly
accessible. "Directly accessible" here means that an unqualified refe... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ccf31c50-2c71-4d04-a850-e04a8d7d64ec | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,807 | supabase-export-v2 | 3563ac67240391a5 | (which is default) didn't change *scope_test*\'s binding of *spam*. The :keyword:`nonlocal` assignment changed *scope_test*\'s binding of *spam*, and the :keyword:`global` assignment changed the module-level binding.
You can also see that there was no previous binding for *spam* before the
:keyword:`global` assignment. | trusted_official_docs | CPython Docs | (which is default) didn't change *scope_test*\'s binding of *spam*. The :keyword:`nonlocal` assignment changed *scope_test*\'s binding of *spam*, and the :keyword:`global` assignment changed the module-level binding.
You can also see that there was no previous binding for *spam* before the
:keyword:`global` assignment. | (which is default) didn't change *scope_test*\'s binding of *spam*. The :keyword:`nonlocal` assignment changed *scope_test*\'s binding of *spam*, and the :keyword:`global` assignment changed the module-level binding.
You can also see that there was no previous binding for *spam* before the
:keyword:`global` assignment. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cd0f615d-4a58-4b1b-8167-9ede85ef9767 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,963 | supabase-export-v2 | 979553b244424438 | >>> x = [[1,2,3], [], [4, 5]] >>> g = (*i for i in x) >>> list(g) [1, 2, 3, 4, 5]
In most cases, generator expressions must be wrapped in parentheses. As a
special case, however, when provided as the sole argument to a function (as in
the examples involving ``sum``, ``set``, ``max``, and ``list`` above), the
generator ... | trusted_official_docs | CPython Docs | >>> x = [[1,2,3], [], [4, 5]] >>> g = (*i for i in x) >>> list(g) [1, 2, 3, 4, 5]
In most cases, generator expressions must be wrapped in parentheses. As a
special case, however, when provided as the sole argument to a function (as in
the examples involving ``sum``, ``set``, ``max``, and ``list`` above), the
generator ... | >>> x = [[1,2,3], [], [4, 5]] >>> g = (*i for i in x) >>> list(g) [1, 2, 3, 4, 5]
In most cases, generator expressions must be wrapped in parentheses. As a
special case, however, when provided as the sole argument to a function (as in
the examples involving ``sum``, ``set``, ``max``, and ``list`` above), the
generator ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cf2e54f8-7cf8-4d94-8f2b-fe06400aee42 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,789 | supabase-export-v2 | 4b5531a8268e19ba | scopes are determined statically, they are used dynamically. At any time during execution, there are 3 or 4 nested scopes whose namespaces are directly accessible:
* the innermost scope, which is searched first, contains the local names
* the scopes of any enclosing functions, which are searched starting with the
near... | trusted_official_docs | CPython Docs | scopes are determined statically, they are used dynamically. At any time during execution, there are 3 or 4 nested scopes whose namespaces are directly accessible:
* the innermost scope, which is searched first, contains the local names
* the scopes of any enclosing functions, which are searched starting with the
near... | scopes are determined statically, they are used dynamically. At any time during execution, there are 3 or 4 nested scopes whose namespaces are directly accessible:
* the innermost scope, which is searched first, contains the local names
* the scopes of any enclosing functions, which are searched starting with the
near... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d1cc1e05-18da-46ce-adcb-e0ac281453ac | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,908 | supabase-export-v2 | 4c66cf1b7256154d | order of its parents). Taken together, these properties make it possible to design reliable and extensible classes with multiple inheritance. For more detail, see :ref:`python_2.3_mro`.
In some cases multiple inheritance is not allowed; see :ref:`multiple-inheritance`
for details. | trusted_official_docs | CPython Docs | order of its parents). Taken together, these properties make it possible to design reliable and extensible classes with multiple inheritance. For more detail, see :ref:`python_2.3_mro`.
In some cases multiple inheritance is not allowed; see :ref:`multiple-inheritance`
for details. | order of its parents). Taken together, these properties make it possible to design reliable and extensible classes with multiple inheritance. For more detail, see :ref:`python_2.3_mro`.
In some cases multiple inheritance is not allowed; see :ref:`multiple-inheritance`
for details. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d303020b-5573-4973-8e09-771a3da0e814 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,875 | supabase-export-v2 | a947529117fd6390 | C, can completely hide implementation details and control access to an object if necessary; this can be used by extensions to Python written in C.)
Clients should use data attributes with care --- clients may mess up invariants
maintained by the methods by stamping on their data attributes. Note that
clients may add da... | trusted_official_docs | CPython Docs | C, can completely hide implementation details and control access to an object if necessary; this can be used by extensions to Python written in C.)
Clients should use data attributes with care --- clients may mess up invariants
maintained by the methods by stamping on their data attributes. Note that
clients may add da... | C, can completely hide implementation details and control access to an object if necessary; this can be used by extensions to Python written in C.)
Clients should use data attributes with care --- clients may mess up invariants
maintained by the methods by stamping on their data attributes. Note that
clients may add da... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
df926086-7a1f-44ee-a3ff-85163fa941b5 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,794 | supabase-export-v2 | c49026a9a3bd9dc2 | that introduce new names use the local scope: in particular, :keyword:`import` statements and function definitions bind the module or function name in the local scope.
The :keyword:`global` statement can be used to indicate that particular
variables live in the global scope and should be rebound there; the
:keyword:`no... | trusted_official_docs | CPython Docs | that introduce new names use the local scope: in particular, :keyword:`import` statements and function definitions bind the module or function name in the local scope.
The :keyword:`global` statement can be used to indicate that particular
variables live in the global scope and should be rebound there; the
:keyword:`no... | that introduce new names use the local scope: in particular, :keyword:`import` statements and function definitions bind the module or function name in the local scope.
The :keyword:`global` statement can be used to indicate that particular
variables live in the global scope and should be rebound there; the
:keyword:`no... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e102d078-4251-49ca-b2c3-e97f18368bd3 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,898 | supabase-export-v2 | 60783ceebfa12528 | This is occasionally useful to clients as well. (Note that this only works if the base class is accessible as ``BaseClassName`` in the global scope.)
Python has two built-in functions that work with inheritance: | trusted_official_docs | CPython Docs | This is occasionally useful to clients as well. (Note that this only works if the base class is accessible as ``BaseClassName`` in the global scope.)
Python has two built-in functions that work with inheritance: | This is occasionally useful to clients as well. (Note that this only works if the base class is accessible as ``BaseClassName`` in the global scope.)
Python has two built-in functions that work with inheritance: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e5835d6a-0556-4aab-89a4-099cd341ea5f | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,815 | supabase-export-v2 | c293226df2878483 | class ClassName: <statement-1> . . . <statement-N>
Class definitions, like function definitions (:keyword:`def` statements) must be
executed before they have any effect. (You could conceivably place a class
definition in a branch of an :keyword:`if` statement, or inside a function.) | trusted_official_docs | CPython Docs | class ClassName: <statement-1> . . . <statement-N>
Class definitions, like function definitions (:keyword:`def` statements) must be
executed before they have any effect. (You could conceivably place a class
definition in a branch of an :keyword:`if` statement, or inside a function.) | class ClassName: <statement-1> . . . <statement-N>
Class definitions, like function definitions (:keyword:`def` statements) must be
executed before they have any effect. (You could conceivably place a class
definition in a branch of an :keyword:`if` statement, or inside a function.) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e952063e-eec3-47fc-82de-2c10664b363a | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,792 | supabase-export-v2 | 152a7e3c1bea886b | functions, the local scope references the same namespace as the global scope: the module's namespace. Class definitions place yet another namespace in the local scope.
It is important to realize that scopes are determined textually: the global
scope of a function defined in a module is that module's namespace, no matte... | trusted_official_docs | CPython Docs | functions, the local scope references the same namespace as the global scope: the module's namespace. Class definitions place yet another namespace in the local scope.
It is important to realize that scopes are determined textually: the global
scope of a function defined in a module is that module's namespace, no matte... | functions, the local scope references the same namespace as the global scope: the module's namespace. Class definitions place yet another namespace in the local scope.
It is important to realize that scopes are determined textually: the global
scope of a function defined in a module is that module's namespace, no matte... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ec24bd40-08ed-42d1-a5a4-dd1c4fdedbd5 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,962 | supabase-export-v2 | 888c93d8aa1f257d | >>> data = 'golf' >>> list(data[i] for i in range(len(data)-1, -1, -1)) ['f', 'l', 'o', 'g']
>>> x = [[1,2,3], [], [4, 5]]
>>> g = (*i for i in x)
>>> list(g)
[1, 2, 3, 4, 5] | trusted_official_docs | CPython Docs | >>> data = 'golf' >>> list(data[i] for i in range(len(data)-1, -1, -1)) ['f', 'l', 'o', 'g']
>>> x = [[1,2,3], [], [4, 5]]
>>> g = (*i for i in x)
>>> list(g)
[1, 2, 3, 4, 5] | >>> data = 'golf' >>> list(data[i] for i in range(len(data)-1, -1, -1)) ['f', 'l', 'o', 'g']
>>> x = [[1,2,3], [], [4, 5]]
>>> g = (*i for i in x)
>>> list(g)
[1, 2, 3, 4, 5] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ec505667-eb9d-482b-ab0f-7eac4233de7b | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,825 | supabase-export-v2 | 1f5da3ab69a8e068 | can change the value of ``MyClass.i`` by assignment. :attr:`~type.__doc__` is also a valid attribute, returning the docstring belonging to the class: ``"A simple example class"``.
Class *instantiation* uses function notation. Just pretend that the class
object is a parameterless function that returns a new instance of ... | trusted_official_docs | CPython Docs | can change the value of ``MyClass.i`` by assignment. :attr:`~type.__doc__` is also a valid attribute, returning the docstring belonging to the class: ``"A simple example class"``.
Class *instantiation* uses function notation. Just pretend that the class
object is a parameterless function that returns a new instance of ... | can change the value of ``MyClass.i`` by assignment. :attr:`~type.__doc__` is also a valid attribute, returning the docstring belonging to the class: ``"A simple example class"``.
Class *instantiation* uses function notation. Just pretend that the class
object is a parameterless function that returns a new instance of ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ed9b8d7d-18a1-4298-93e3-df4b66105818 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,932 | supabase-export-v2 | 12a26f76a9aa088d | you can define a class with methods :meth:`~io.TextIOBase.read` and :meth:`~io.TextIOBase.readline` that get the data from a string buffer instead, and pass it as an argument.
.. (Unfortunately, this technique has its limitations: a class can't define
operations that are accessed by special syntax such as sequence sub... | trusted_official_docs | CPython Docs | you can define a class with methods :meth:`~io.TextIOBase.read` and :meth:`~io.TextIOBase.readline` that get the data from a string buffer instead, and pass it as an argument.
.. (Unfortunately, this technique has its limitations: a class can't define
operations that are accessed by special syntax such as sequence sub... | you can define a class with methods :meth:`~io.TextIOBase.read` and :meth:`~io.TextIOBase.readline` that get the data from a string buffer instead, and pass it as an argument.
.. (Unfortunately, this technique has its limitations: a class can't define
operations that are accessed by special syntax such as sequence sub... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ef08fd6c-5956-4f32-94c2-f663861f4489 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,817 | supabase-export-v2 | cb9ef24cab3f125b | definitions inside a class normally have a peculiar form of argument list, dictated by the calling conventions for methods --- again, this is explained later.
When a class definition is entered, a new namespace is created, and used as the
local scope --- thus, all assignments to local variables go into this new
namespa... | trusted_official_docs | CPython Docs | definitions inside a class normally have a peculiar form of argument list, dictated by the calling conventions for methods --- again, this is explained later.
When a class definition is entered, a new namespace is created, and used as the
local scope --- thus, all assignments to local variables go into this new
namespa... | definitions inside a class normally have a peculiar form of argument list, dictated by the calling conventions for methods --- again, this is explained later.
When a class definition is entered, a new namespace is created, and used as the
local scope --- thus, all assignments to local variables go into this new
namespa... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f9adef76-12de-4cb0-a743-17a780b19e8c | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,806 | supabase-export-v2 | acb302768129d8bd | After local assignment: test spam After nonlocal assignment: nonlocal spam After global assignment: nonlocal spam In global scope: global spam
Note how the *local* assignment (which is default) didn't change *scope_test*\'s
binding of *spam*. The :keyword:`nonlocal` assignment changed *scope_test*\'s
binding of *spam*,... | trusted_official_docs | CPython Docs | After local assignment: test spam After nonlocal assignment: nonlocal spam After global assignment: nonlocal spam In global scope: global spam
Note how the *local* assignment (which is default) didn't change *scope_test*\'s
binding of *spam*. The :keyword:`nonlocal` assignment changed *scope_test*\'s
binding of *spam*,... | After local assignment: test spam After nonlocal assignment: nonlocal spam After global assignment: nonlocal spam In global scope: global spam
Note how the *local* assignment (which is default) didn't change *scope_test*\'s
binding of *spam*. The :keyword:`nonlocal` assignment changed *scope_test*\'s
binding of *spam*,... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f9bd71de-8770-47c9-9b39-98d386254549 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,828 | supabase-export-v2 | f77789085f314e8a | creates a new *instance* of the class and assigns this object to the local variable ``x``.
The instantiation operation ("calling" a class object) creates an empty object. Many classes like to create objects with instances customized to a specific
initial state. Therefore a class may define a special method named
:meth:... | trusted_official_docs | CPython Docs | creates a new *instance* of the class and assigns this object to the local variable ``x``.
The instantiation operation ("calling" a class object) creates an empty object. Many classes like to create objects with instances customized to a specific
initial state. Therefore a class may define a special method named
:meth:... | creates a new *instance* of the class and assigns this object to the local variable ``x``.
The instantiation operation ("calling" a class object) creates an empty object. Many classes like to create objects with instances customized to a specific
initial state. Therefore a class may define a special method named
:meth:... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fd221602-7aaa-491e-975e-cd1fb9ac4612 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,773 | supabase-export-v2 | c887c0360b00e3a7 | As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and can be modified further after creation.
In C++ terminology, normally class members (including the data members) are
*public* (except see below :ref:`tut-private`), and all member functions are
*virtual*. As in Modu... | trusted_official_docs | CPython Docs | As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and can be modified further after creation.
In C++ terminology, normally class members (including the data members) are
*public* (except see below :ref:`tut-private`), and all member functions are
*virtual*. As in Modu... | As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and can be modified further after creation.
In C++ terminology, normally class members (including the data members) are
*public* (except see below :ref:`tut-private`), and all member functions are
*virtual*. As in Modu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ffd20f4c-516a-42f2-9c85-531994f8a742 | CPython Docs | file://datasets/cpython/Doc/tutorial/classes.rst | unknown | b594dc57-f00f-4188-81c5-6e58c66a5d7f | 52,913 | supabase-export-v2 | 191947dec1e2e997 | .. index:: pair: name; mangling
Since there is a valid use-case for class-private members (namely to avoid name
clashes of names with names defined by subclasses), there is limited support for
such a mechanism, called :dfn:`name mangling`. Any identifier of the form
``__spam`` (at least two leading underscores, at most... | trusted_official_docs | CPython Docs | .. index:: pair: name; mangling
Since there is a valid use-case for class-private members (namely to avoid name
clashes of names with names defined by subclasses), there is limited support for
such a mechanism, called :dfn:`name mangling`. Any identifier of the form
``__spam`` (at least two leading underscores, at most... | .. index:: pair: name; mangling
Since there is a valid use-case for class-private members (namely to avoid name
clashes of names with names defined by subclasses), there is limited support for
such a mechanism, called :dfn:`name mangling`. Any identifier of the form
``__spam`` (at least two leading underscores, at most... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
09e12512-4d06-4be9-a046-af1dadaf46ea | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,010 | supabase-export-v2 | a22da969f224f8f2 | it's possible to prevent this by adding a ``\`` at the end of the line. In the following example, the initial newline is not included::
>>> print("""\
... Usage: thingy [OPTIONS]
... -h Display this usage message
... -H hostname Hostname to connect to
... """)
Usage: thingy [OPTIONS]
-h Display this usage message... | trusted_official_docs | CPython Docs | it's possible to prevent this by adding a ``\`` at the end of the line. In the following example, the initial newline is not included::
>>> print("""\
... Usage: thingy [OPTIONS]
... -h Display this usage message
... -H hostname Hostname to connect to
... """)
Usage: thingy [OPTIONS]
-h Display this usage message... | it's possible to prevent this by adding a ``\`` at the end of the line. In the following example, the initial newline is not included::
>>> print("""\
... Usage: thingy [OPTIONS]
... -h Display this usage message
... -H hostname Hostname to connect to
... """)
Usage: thingy [OPTIONS]
-h Display this usage message... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0a02ab14-9f86-4ec9-8de6-b35998626307 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,973 | supabase-export-v2 | 01e135de3d76a8e3 | corner when hovering over or tapping a code example), which strips prompts and omits output, to copy and paste the input lines into your interpreter.
.. index:: single: # (hash); comment | trusted_official_docs | CPython Docs | corner when hovering over or tapping a code example), which strips prompts and omits output, to copy and paste the input lines into your interpreter.
.. index:: single: # (hash); comment | corner when hovering over or tapping a code example), which strips prompts and omits output, to copy and paste the input lines into your interpreter.
.. index:: single: # (hash); comment | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0c91fc38-865f-4a05-8c96-bba99fff3731 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,065 | supabase-export-v2 | fcc96330a16c2dcd | to the *existing list*. Any changes you make to the list through one variable will be seen through all other variables that refer to it.::
>>> rgb = ["Red", "Green", "Blue"]
>>> rgba = rgb
>>> id(rgb) == id(rgba) # they reference the same object
True
>>> rgba.append("Alph")
>>> rgb
["Red", "Green", "Blue", "Alph"... | trusted_official_docs | CPython Docs | to the *existing list*. Any changes you make to the list through one variable will be seen through all other variables that refer to it.::
>>> rgb = ["Red", "Green", "Blue"]
>>> rgba = rgb
>>> id(rgb) == id(rgba) # they reference the same object
True
>>> rgba.append("Alph")
>>> rgb
["Red", "Green", "Blue", "Alph"... | to the *existing list*. Any changes you make to the list through one variable will be seen through all other variables that refer to it.::
>>> rgb = ["Red", "Green", "Blue"]
>>> rgba = rgb
>>> id(rgb) == id(rgba) # they reference the same object
True
>>> rgba.append("Alph")
>>> rgb
["Red", "Green", "Blue", "Alph"... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0cf8ea80-0a15-420c-ad05-7c13bdbb9c5a | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,062 | supabase-export-v2 | 313688b20fa93970 | the cube of 4 is 64, not 65! 64 >>> cubes[3] = 64 # replace the wrong value >>> cubes [1, 8, 27, 64, 125]
You can also add new items at the end of the list, by using
the :meth:`list.append` *method* (we will see more about methods later):: | trusted_official_docs | CPython Docs | the cube of 4 is 64, not 65! 64 >>> cubes[3] = 64 # replace the wrong value >>> cubes [1, 8, 27, 64, 125]
You can also add new items at the end of the list, by using
the :meth:`list.append` *method* (we will see more about methods later):: | the cube of 4 is 64, not 65! 64 >>> cubes[3] = 64 # replace the wrong value >>> cubes [1, 8, 27, 64, 125]
You can also add new items at the end of the list, by using
the :meth:`list.append` *method* (we will see more about methods later):: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0dbb5635-d48a-4a43-be9a-ba67bdad9c67 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,034 | supabase-export-v2 | 511ad692b34d1a36 | of the first character numbered 0. Then the right edge of the last character of a string of *n* characters has index *n*, for example::
+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1 | trusted_official_docs | CPython Docs | of the first character numbered 0. Then the right edge of the last character of a string of *n* characters has index *n*, for example::
+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1 | of the first character numbered 0. Then the right edge of the last character of a string of *n* characters has index *n*, for example::
+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1cf6b2b8-b83a-4198-969e-678c05672b20 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,994 | supabase-export-v2 | b8ab5b81e4f4c95d | >>> 4 * 3.75 - 1 14.0
In interactive mode, the last printed expression is assigned to the variable
``_``. This means that when you are using Python as a desk calculator, it is
somewhat easier to continue calculations, for example:: | trusted_official_docs | CPython Docs | >>> 4 * 3.75 - 1 14.0
In interactive mode, the last printed expression is assigned to the variable
``_``. This means that when you are using Python as a desk calculator, it is
somewhat easier to continue calculations, for example:: | >>> 4 * 3.75 - 1 14.0
In interactive mode, the last printed expression is assigned to the variable
``_``. This means that when you are using Python as a desk calculator, it is
somewhat easier to continue calculations, for example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1d01474e-ce29-4f8d-a8e4-301154d36c27 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,039 | supabase-export-v2 | bb3cf0c3d6cabe9b | word[42] # the word only has 6 characters Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: string index out of range
However, out of range slice indexes are handled gracefully when used for
slicing:: | trusted_official_docs | CPython Docs | word[42] # the word only has 6 characters Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: string index out of range
However, out of range slice indexes are handled gracefully when used for
slicing:: | word[42] # the word only has 6 characters Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: string index out of range
However, out of range slice indexes are handled gracefully when used for
slicing:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2055c278-a383-4623-a44f-37433dce5cc4 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,970 | supabase-export-v2 | cccc5105a3a3eff0 | ********************************** An Informal Introduction to Python **********************************
In the following examples, input and output are distinguished by the presence or
absence of prompts (:term:`>>>` and :term:`...`): to repeat the example, you must type
everything after the prompt, when the prompt ap... | trusted_official_docs | CPython Docs | ********************************** An Informal Introduction to Python **********************************
In the following examples, input and output are distinguished by the presence or
absence of prompts (:term:`>>>` and :term:`...`): to repeat the example, you must type
everything after the prompt, when the prompt ap... | ********************************** An Informal Introduction to Python **********************************
In the following examples, input and output are distinguished by the presence or
absence of prompts (:term:`>>>` and :term:`...`): to repeat the example, you must type
everything after the prompt, when the prompt ap... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2267ea97-00e0-4e46-ad53-0f8e9abfdf91 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,068 | supabase-export-v2 | af1435c35874d28e | >>> correct_rgba = rgba[:] >>> correct_rgba[-1] = "Alpha" >>> correct_rgba ["Red", "Green", "Blue", "Alpha"] >>> rgba ["Red", "Green", "Blue", "Alph"]
Assignment to slices is also possible, and this can even change the size of the
list or clear it entirely:: | trusted_official_docs | CPython Docs | >>> correct_rgba = rgba[:] >>> correct_rgba[-1] = "Alpha" >>> correct_rgba ["Red", "Green", "Blue", "Alpha"] >>> rgba ["Red", "Green", "Blue", "Alph"]
Assignment to slices is also possible, and this can even change the size of the
list or clear it entirely:: | >>> correct_rgba = rgba[:] >>> correct_rgba[-1] = "Alpha" >>> correct_rgba ["Red", "Green", "Blue", "Alpha"] >>> rgba ["Red", "Green", "Blue", "Alph"]
Assignment to slices is also possible, and this can even change the size of the
list or clear it entirely:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
228443a0-2b25-467c-8092-dfbcff15625c | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,996 | supabase-export-v2 | 91d04ad37a423d4a | >>> tax = 12.5 / 100 >>> price = 100.50 >>> price * tax 12.5625 >>> price + _ 113.0625 >>> round(_, 2) 113.06
This variable should be treated as read-only by the user. Don't explicitly
assign a value to it --- you would create an independent local variable with the
same name masking the built-in variable with its magic... | trusted_official_docs | CPython Docs | >>> tax = 12.5 / 100 >>> price = 100.50 >>> price * tax 12.5625 >>> price + _ 113.0625 >>> round(_, 2) 113.06
This variable should be treated as read-only by the user. Don't explicitly
assign a value to it --- you would create an independent local variable with the
same name masking the built-in variable with its magic... | >>> tax = 12.5 / 100 >>> price = 100.50 >>> price * tax 12.5625 >>> price + _ 113.0625 >>> round(_, 2) 113.06
This variable should be treated as read-only by the user. Don't explicitly
assign a value to it --- you would create an independent local variable with the
same name masking the built-in variable with its magic... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
263ff1f0-5ff1-48da-95b7-efb8dbf908b3 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,055 | supabase-export-v2 | 28663d4fcfdaa7ee | list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type. ::
>>> squares = [1, 4, 9, 16, 25]
>>> squares
[1, 4, 9, 16, 25] | trusted_official_docs | CPython Docs | list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type. ::
>>> squares = [1, 4, 9, 16, 25]
>>> squares
[1, 4, 9, 16, 25] | list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type. ::
>>> squares = [1, 4, 9, 16, 25]
>>> squares
[1, 4, 9, 16, 25] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
26e63896-3148-4669-a77c-ab687ef2adcd | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,990 | supabase-export-v2 | 9544e540dadb502f | >>> width = 20 >>> height = 5 * 9 >>> width * height 900
If a variable is not "defined" (assigned a value), trying to use it will
give you an error:: | trusted_official_docs | CPython Docs | >>> width = 20 >>> height = 5 * 9 >>> width * height 900
If a variable is not "defined" (assigned a value), trying to use it will
give you an error:: | >>> width = 20 >>> height = 5 * 9 >>> width * height 900
If a variable is not "defined" (assigned a value), trying to use it will
give you an error:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
339b896e-6a86-4659-9d43-c8e79b8008e8 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,018 | supabase-export-v2 | 53da26cfd48c0188 | = ('Put several strings within parentheses ' ... 'to have them joined together.') >>> text 'Put several strings within parentheses to have them joined together.'
This only works with two literals though, not with variables or expressions:: | trusted_official_docs | CPython Docs | = ('Put several strings within parentheses ' ... 'to have them joined together.') >>> text 'Put several strings within parentheses to have them joined together.'
This only works with two literals though, not with variables or expressions:: | = ('Put several strings within parentheses ' ... 'to have them joined together.') >>> text 'Put several strings within parentheses to have them joined together.'
This only works with two literals though, not with variables or expressions:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
44517b38-97ca-4e10-8950-c80288f58004 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,981 | supabase-export-v2 | 4572bfc60000f369 | Numbers -------
The interpreter acts as a simple calculator: you can type an expression into it
and it will write the value. Expression syntax is straightforward: the
operators ``+``, ``-``, ``*`` and ``/`` can be used to perform
arithmetic; parentheses (``()``) can be used for grouping. For example:: | trusted_official_docs | CPython Docs | Numbers -------
The interpreter acts as a simple calculator: you can type an expression into it
and it will write the value. Expression syntax is straightforward: the
operators ``+``, ``-``, ``*`` and ``/`` can be used to perform
arithmetic; parentheses (``()``) can be used for grouping. For example:: | Numbers -------
The interpreter acts as a simple calculator: you can type an expression into it
and it will write the value. Expression syntax is straightforward: the
operators ``+``, ``-``, ``*`` and ``/`` can be used to perform
arithmetic; parentheses (``()``) can be used for grouping. For example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
44f9780f-568e-4355-974c-262d3a564e27 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,997 | supabase-export-v2 | 652c60305444f776 | assign a value to it --- you would create an independent local variable with the same name masking the built-in variable with its magic behavior.
In addition to :class:`int` and :class:`float`, Python supports other types of
numbers, such as :class:`~decimal.Decimal` and :class:`~fractions.Fraction`. Python also has bu... | trusted_official_docs | CPython Docs | assign a value to it --- you would create an independent local variable with the same name masking the built-in variable with its magic behavior.
In addition to :class:`int` and :class:`float`, Python supports other types of
numbers, such as :class:`~decimal.Decimal` and :class:`~fractions.Fraction`. Python also has bu... | assign a value to it --- you would create an independent local variable with the same name masking the built-in variable with its magic behavior.
In addition to :class:`int` and :class:`float`, Python supports other types of
numbers, such as :class:`~decimal.Decimal` and :class:`~fractions.Fraction`. Python also has bu... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
461c4610-f04d-4645-87be-406e3e0b2231 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,063 | supabase-export-v2 | 37362058e0e1bf17 | You can also add new items at the end of the list, by using the :meth:`list.append` *method* (we will see more about methods later)::
>>> cubes.append(216) # add the cube of 6
>>> cubes.append(7 ** 3) # and the cube of 7
>>> cubes
[1, 8, 27, 64, 125, 216, 343] | trusted_official_docs | CPython Docs | You can also add new items at the end of the list, by using the :meth:`list.append` *method* (we will see more about methods later)::
>>> cubes.append(216) # add the cube of 6
>>> cubes.append(7 ** 3) # and the cube of 7
>>> cubes
[1, 8, 27, 64, 125, 216, 343] | You can also add new items at the end of the list, by using the :meth:`list.append` *method* (we will see more about methods later)::
>>> cubes.append(216) # add the cube of 6
>>> cubes.append(7 ** 3) # and the cube of 7
>>> cubes
[1, 8, 27, 64, 125, 216, 343] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4a7b2df9-082c-436c-9608-a60c6e146661 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,061 | supabase-export-v2 | 61e0af48ea5bf0ba | Unlike strings, which are :term:`immutable`, lists are a :term:`mutable` type, i.e. it is possible to change their content::
>>> cubes = [1, 8, 27, 65, 125] # something's wrong here
>>> 4 ** 3 # the cube of 4 is 64, not 65! 64
>>> cubes[3] = 64 # replace the wrong value
>>> cubes
[1, 8, 27, 64, 125] | trusted_official_docs | CPython Docs | Unlike strings, which are :term:`immutable`, lists are a :term:`mutable` type, i.e. it is possible to change their content::
>>> cubes = [1, 8, 27, 65, 125] # something's wrong here
>>> 4 ** 3 # the cube of 4 is 64, not 65! 64
>>> cubes[3] = 64 # replace the wrong value
>>> cubes
[1, 8, 27, 64, 125] | Unlike strings, which are :term:`immutable`, lists are a :term:`mutable` type, i.e. it is possible to change their content::
>>> cubes = [1, 8, 27, 65, 125] # something's wrong here
>>> 4 ** 3 # the cube of 4 is 64, not 65! 64
>>> cubes[3] = 64 # replace the wrong value
>>> cubes
[1, 8, 27, 64, 125] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4c141f8e-6113-404f-9893-d97b411874d3 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,079 | supabase-export-v2 | 513cb695ebb013fc | This example introduces several new features.
* The first line contains a *multiple assignment*: the variables ``a`` and ``b``
simultaneously get the new values 0 and 1. On the last line this is used again,
demonstrating that the expressions on the right-hand side are all evaluated
first before any of the assignment... | trusted_official_docs | CPython Docs | This example introduces several new features.
* The first line contains a *multiple assignment*: the variables ``a`` and ``b``
simultaneously get the new values 0 and 1. On the last line this is used again,
demonstrating that the expressions on the right-hand side are all evaluated
first before any of the assignment... | This example introduces several new features.
* The first line contains a *multiple assignment*: the variables ``a`` and ``b``
simultaneously get the new values 0 and 1. On the last line this is used again,
demonstrating that the expressions on the right-hand side are all evaluated
first before any of the assignment... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5008d22d-9be0-44b4-a812-33e265ac8f58 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,037 | supabase-export-v2 | 6c7df71177c82308 | indices, the length of a slice is the difference of the indices, if both are within bounds. For example, the length of ``word[1:3]`` is 2.
Attempting to use an index that is too large will result in an error:: | trusted_official_docs | CPython Docs | indices, the length of a slice is the difference of the indices, if both are within bounds. For example, the length of ``word[1:3]`` is 2.
Attempting to use an index that is too large will result in an error:: | indices, the length of a slice is the difference of the indices, if both are within bounds. For example, the length of ``word[1:3]`` is 2.
Attempting to use an index that is too large will result in an error:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
517b6da1-6553-44d8-93eb-b23ad5e3ddf7 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,031 | supabase-export-v2 | 71e396da16240599 | 'Py' >>> word[4:] # characters from position 4 (included) to the end 'on' >>> word[-2:] # characters from the second-last (included) to the end 'on'
Note how the start is always included, and the end always excluded. This
makes sure that ``s[:i] + s[i:]`` is always equal to ``s``:: | trusted_official_docs | CPython Docs | 'Py' >>> word[4:] # characters from position 4 (included) to the end 'on' >>> word[-2:] # characters from the second-last (included) to the end 'on'
Note how the start is always included, and the end always excluded. This
makes sure that ``s[:i] + s[i:]`` is always equal to ``s``:: | 'Py' >>> word[4:] # characters from position 4 (included) to the end 'on' >>> word[-2:] # characters from the second-last (included) to the end 'on'
Note how the start is always included, and the end always excluded. This
makes sure that ``s[:i] + s[i:]`` is always equal to ``s``:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
52df8da0-ae3d-4e79-bbc8-059b21196b25 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,070 | supabase-export-v2 | b6ef6d5becb25ecb | ['a', 'b', 'f', 'g'] >>> # clear the list by replacing all the elements with an empty list >>> letters[:] = [] >>> letters []
The built-in function :func:`len` also applies to lists:: | trusted_official_docs | CPython Docs | ['a', 'b', 'f', 'g'] >>> # clear the list by replacing all the elements with an empty list >>> letters[:] = [] >>> letters []
The built-in function :func:`len` also applies to lists:: | ['a', 'b', 'f', 'g'] >>> # clear the list by replacing all the elements with an empty list >>> letters[:] = [] >>> letters []
The built-in function :func:`len` also applies to lists:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
556fe935-04b1-4030-a3f6-edf26337a1c1 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,042 | supabase-export-v2 | ab37df6104e0cb58 | Python strings cannot be changed --- they are :term:`immutable`. Therefore, assigning to an indexed position in the string results in an error::
>>> word[0] = 'J'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> word[2:] = 'py'
Trac... | trusted_official_docs | CPython Docs | Python strings cannot be changed --- they are :term:`immutable`. Therefore, assigning to an indexed position in the string results in an error::
>>> word[0] = 'J'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> word[2:] = 'py'
Trac... | Python strings cannot be changed --- they are :term:`immutable`. Therefore, assigning to an indexed position in the string results in an error::
>>> word[0] = 'J'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> word[2:] = 'py'
Trac... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
56f4f58e-0243-407e-b10d-d3801a9f314c | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,032 | supabase-export-v2 | c6ee48782c211971 | Note how the start is always included, and the end always excluded. This makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
>>> word[:2] + word[2:]
'Python'
>>> word[:4] + word[4:]
'Python' | trusted_official_docs | CPython Docs | Note how the start is always included, and the end always excluded. This makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
>>> word[:2] + word[2:]
'Python'
>>> word[:4] + word[4:]
'Python' | Note how the start is always included, and the end always excluded. This makes sure that ``s[:i] + s[i:]`` is always equal to ``s``::
>>> word[:2] + word[2:]
'Python'
>>> word[:4] + word[4:]
'Python' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5815523b-029e-4cfb-840a-c83134b7012f | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,035 | supabase-export-v2 | a4ed978a3191c609 | | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6 -6 -5 -4 -3 -2 -1
The first row of numbers gives the position of the indices 0...6 in the string;
the second row gives the corresponding negative indices. The slice from *i* to
*j* consists of all characters between the edges labeled *i* and *j*,
respectivel... | trusted_official_docs | CPython Docs | | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6 -6 -5 -4 -3 -2 -1
The first row of numbers gives the position of the indices 0...6 in the string;
the second row gives the corresponding negative indices. The slice from *i* to
*j* consists of all characters between the edges labeled *i* and *j*,
respectivel... | | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6 -6 -5 -4 -3 -2 -1
The first row of numbers gives the position of the indices 0...6 in the string;
the second row gives the corresponding negative indices. The slice from *i* to
*j* consists of all characters between the edges labeled *i* and *j*,
respectivel... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5978f140-a915-43dc-9b0f-0a23b5d70d7c | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,027 | supabase-export-v2 | 68f349fcf3edef31 | Note that since -0 is the same as 0, negative indices start from -1.
In addition to indexing, *slicing* is also supported. While indexing is used
to obtain individual characters, *slicing* allows you to obtain a substring:: | trusted_official_docs | CPython Docs | Note that since -0 is the same as 0, negative indices start from -1.
In addition to indexing, *slicing* is also supported. While indexing is used
to obtain individual characters, *slicing* allows you to obtain a substring:: | Note that since -0 is the same as 0, negative indices start from -1.
In addition to indexing, *slicing* is also supported. While indexing is used
to obtain individual characters, *slicing* allows you to obtain a substring:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5b5be550-d6a0-4bc2-841d-389ecdc3930c | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,003 | supabase-export-v2 | fb899e4938af1505 | To quote a quote, we need to "escape" it, by preceding it with ``\``. Alternatively, we can use the other type of quotation marks::
>>> 'doesn\'t' # use \' to escape the single quote... "doesn't"
>>> "doesn't" # ...or use double quotes instead
"doesn't"
>>> '"Yes," they said.'
'"Yes," they said.'
>>> "\"Yes,\" the... | trusted_official_docs | CPython Docs | To quote a quote, we need to "escape" it, by preceding it with ``\``. Alternatively, we can use the other type of quotation marks::
>>> 'doesn\'t' # use \' to escape the single quote... "doesn't"
>>> "doesn't" # ...or use double quotes instead
"doesn't"
>>> '"Yes," they said.'
'"Yes," they said.'
>>> "\"Yes,\" the... | To quote a quote, we need to "escape" it, by preceding it with ``\``. Alternatively, we can use the other type of quotation marks::
>>> 'doesn\'t' # use \' to escape the single quote... "doesn't"
>>> "doesn't" # ...or use double quotes instead
"doesn't"
>>> '"Yes," they said.'
'"Yes," they said.'
>>> "\"Yes,\" the... | 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.