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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5b600176-80e2-4ffd-b835-0bfa00229eea | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,023 | supabase-export-v2 | d26bb8b7d6f9bdb0 | be *indexed* (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size one::
>>> word = 'Python'
>>> word[0] # character in position 0
'P'
>>> word[5] # character in position 5
'n' | trusted_official_docs | CPython Docs | be *indexed* (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size one::
>>> word = 'Python'
>>> word[0] # character in position 0
'P'
>>> word[5] # character in position 5
'n' | be *indexed* (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size one::
>>> word = 'Python'
>>> word[0] # character in position 0
'P'
>>> word[5] # character in position 5
'n' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5bbb9103-00ca-47e0-8bc5-35f40cce9053 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,064 | supabase-export-v2 | 7d0f51cd67163f62 | # add the cube of 6 >>> cubes.append(7 ** 3) # and the cube of 7 >>> cubes [1, 8, 27, 64, 125, 216, 343]
Simple assignment in Python never copies data. When you assign a list
to a variable, the variable refers to the *existing list*. Any changes you make to the list through one variable will be seen
through all other v... | trusted_official_docs | CPython Docs | # add the cube of 6 >>> cubes.append(7 ** 3) # and the cube of 7 >>> cubes [1, 8, 27, 64, 125, 216, 343]
Simple assignment in Python never copies data. When you assign a list
to a variable, the variable refers to the *existing list*. Any changes you make to the list through one variable will be seen
through all other v... | # add the cube of 6 >>> cubes.append(7 ** 3) # and the cube of 7 >>> cubes [1, 8, 27, 64, 125, 216, 343]
Simple assignment in Python never copies data. When you assign a list
to a variable, the variable refers to the *existing list*. Any changes you make to the list through one variable will be seen
through all other v... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5c8de86b-44e2-4388-992d-0c0f58cc3dc0 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,017 | supabase-export-v2 | 8f7ee404902ed8c4 | This feature is particularly useful when you want to break long strings::
>>> text = ('Put several strings within parentheses '
... 'to have them joined together.')
>>> text
'Put several strings within parentheses to have them joined together.' | trusted_official_docs | CPython Docs | This feature is particularly useful when you want to break long strings::
>>> text = ('Put several strings within parentheses '
... 'to have them joined together.')
>>> text
'Put several strings within parentheses to have them joined together.' | This feature is particularly useful when you want to break long strings::
>>> text = ('Put several strings within parentheses '
... 'to have them joined together.')
>>> text
'Put several strings within parentheses to have them joined together.' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5cccc1f7-6e67-4a0a-a652-8bef79b347ec | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,088 | supabase-export-v2 | 87ad5847e3b2eb73 | higher precedence than ``-``, ``-3**2`` will be interpreted as ``-(3**2)`` and thus result in ``-9``. To avoid this and get ``9``, you can use ``(-3)**2``.
.. [#] Unlike other languages, special characters such as ``\n`` have the
same meaning with both single (``'...'``) and double (``"..."``) quotes. The only differe... | trusted_official_docs | CPython Docs | higher precedence than ``-``, ``-3**2`` will be interpreted as ``-(3**2)`` and thus result in ``-9``. To avoid this and get ``9``, you can use ``(-3)**2``.
.. [#] Unlike other languages, special characters such as ``\n`` have the
same meaning with both single (``'...'``) and double (``"..."``) quotes. The only differe... | higher precedence than ``-``, ``-3**2`` will be interpreted as ``-(3**2)`` and thus result in ``-9``. To avoid this and get ``9``, you can use ``(-3)**2``.
.. [#] Unlike other languages, special characters such as ``\n`` have the
same meaning with both single (``'...'``) and double (``"..."``) quotes. The only differe... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5dc1f6f9-e333-4e7b-a707-8eb3f100d57a | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,007 | supabase-export-v2 | e4eea48f7a797383 | don't want characters prefaced by ``\`` to be interpreted as special characters, you can use *raw strings* by adding an ``r`` before the first quote::
>>> print('C:\this\name') # here \t means tab, \n means newline
C: his
ame
>>> print(r'C:\this\name') # note the r before the quote
C:\this\name | trusted_official_docs | CPython Docs | don't want characters prefaced by ``\`` to be interpreted as special characters, you can use *raw strings* by adding an ``r`` before the first quote::
>>> print('C:\this\name') # here \t means tab, \n means newline
C: his
ame
>>> print(r'C:\this\name') # note the r before the quote
C:\this\name | don't want characters prefaced by ``\`` to be interpreted as special characters, you can use *raw strings* by adding an ``r`` before the first quote::
>>> print('C:\this\name') # here \t means tab, \n means newline
C: his
ame
>>> print(r'C:\this\name') # note the r before the quote
C:\this\name | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
61d294a1-b34b-4750-8ce3-38e6ec62c6c1 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,985 | supabase-export-v2 | 85de9b5b5d48e2b7 | a float. To do :term:`floor division` and get an integer result you can use the ``//`` operator; to calculate the remainder you can use ``%``::
>>> 17 / 3 # classic division returns a float
5.666666666666667
>>>
>>> 17 // 3 # floor division discards the fractional part
5
>>> 17 % 3 # the % operator returns the rem... | trusted_official_docs | CPython Docs | a float. To do :term:`floor division` and get an integer result you can use the ``//`` operator; to calculate the remainder you can use ``%``::
>>> 17 / 3 # classic division returns a float
5.666666666666667
>>>
>>> 17 // 3 # floor division discards the fractional part
5
>>> 17 % 3 # the % operator returns the rem... | a float. To do :term:`floor division` and get an integer result you can use the ``//`` operator; to calculate the remainder you can use ``%``::
>>> 17 / 3 # classic division returns a float
5.666666666666667
>>>
>>> 17 // 3 # floor division discards the fractional part
5
>>> 17 % 3 # the % operator returns the rem... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
64cf419b-973f-4215-b02b-44a2635a6c25 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,022 | supabase-export-v2 | f0518f3f33b6bd67 | >>> prefix + 'thon' 'Python'
Strings can be *indexed* (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size
one:: | trusted_official_docs | CPython Docs | >>> prefix + 'thon' 'Python'
Strings can be *indexed* (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size
one:: | >>> prefix + 'thon' 'Python'
Strings can be *indexed* (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size
one:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6f723044-c120-4e15-9071-0c34f576150b | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,019 | supabase-export-v2 | cdb61595291099c8 | This only works with two literals though, not with variables or expressions::
>>> prefix = 'Py'
>>> prefix 'thon' # can't concatenate a variable and a string literal
File "<stdin>", line 1
prefix 'thon'
^^^^^^
SyntaxError: invalid syntax
>>> ('un' * 3) 'ium'
File "<stdin>", line 1
('un' * 3) 'ium'
^^^^^
Synta... | trusted_official_docs | CPython Docs | This only works with two literals though, not with variables or expressions::
>>> prefix = 'Py'
>>> prefix 'thon' # can't concatenate a variable and a string literal
File "<stdin>", line 1
prefix 'thon'
^^^^^^
SyntaxError: invalid syntax
>>> ('un' * 3) 'ium'
File "<stdin>", line 1
('un' * 3) 'ium'
^^^^^
Synta... | This only works with two literals though, not with variables or expressions::
>>> prefix = 'Py'
>>> prefix 'thon' # can't concatenate a variable and a string literal
File "<stdin>", line 1
prefix 'thon'
^^^^^^
SyntaxError: invalid syntax
>>> ('un' * 3) 'ium'
File "<stdin>", line 1
('un' * 3) 'ium'
^^^^^
Synta... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6fdabfd0-c462-4917-901c-08a06d42f714 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,020 | supabase-export-v2 | c7dc44d204cb34eb | line 1 prefix 'thon' ^^^^^^ SyntaxError: invalid syntax >>> ('un' * 3) 'ium' File "<stdin>", line 1 ('un' * 3) 'ium' ^^^^^ SyntaxError: invalid syntax
If you want to concatenate variables or a variable and a literal, use ``+``:: | trusted_official_docs | CPython Docs | line 1 prefix 'thon' ^^^^^^ SyntaxError: invalid syntax >>> ('un' * 3) 'ium' File "<stdin>", line 1 ('un' * 3) 'ium' ^^^^^ SyntaxError: invalid syntax
If you want to concatenate variables or a variable and a literal, use ``+``:: | line 1 prefix 'thon' ^^^^^^ SyntaxError: invalid syntax >>> ('un' * 3) 'ium' File "<stdin>", line 1 ('un' * 3) 'ium' ^^^^^ SyntaxError: invalid syntax
If you want to concatenate variables or a variable and a literal, use ``+``:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
747905b8-6b65-4bf9-b564-15b991b695fa | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,976 | supabase-export-v2 | b4534b02b0949714 | Some examples::
# this is the first comment
spam = 1 # and this is the second comment
# ... and now a third! text = "# This is not a comment because it's inside quotes." | trusted_official_docs | CPython Docs | Some examples::
# this is the first comment
spam = 1 # and this is the second comment
# ... and now a third! text = "# This is not a comment because it's inside quotes." | Some examples::
# this is the first comment
spam = 1 # and this is the second comment
# ... and now a third! text = "# This is not a comment because it's inside quotes." | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7766c99c-fd1d-4067-bcca-3a3e3771fb3d | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,085 | supabase-export-v2 | ff4680f4af6ed5fa | The keyword argument *end* can be used to avoid the newline after the output, or end the output with a different string::
>>> a, b = 0, 1
>>> while a < 1000:
... print(a, end=',')
... a, b = b, a+b
... 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987, | trusted_official_docs | CPython Docs | The keyword argument *end* can be used to avoid the newline after the output, or end the output with a different string::
>>> a, b = 0, 1
>>> while a < 1000:
... print(a, end=',')
... a, b = b, a+b
... 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987, | The keyword argument *end* can be used to avoid the newline after the output, or end the output with a different string::
>>> a, b = 0, 1
>>> while a < 1000:
... print(a, end=',')
... a, b = b, a+b
... 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987, | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
784970fc-597e-48fc-8f65-fe831c6ee63c | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,073 | supabase-export-v2 | 808de6213999fded | It is possible to nest lists (create lists containing other lists), for example::
>>> a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
>>> x[0]
['a', 'b', 'c']
>>> x[0][1]
'b' | trusted_official_docs | CPython Docs | It is possible to nest lists (create lists containing other lists), for example::
>>> a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
>>> x[0]
['a', 'b', 'c']
>>> x[0][1]
'b' | It is possible to nest lists (create lists containing other lists), for example::
>>> a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
>>> x[0]
['a', 'b', 'c']
>>> x[0][1]
'b' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
793cc9f9-dfa6-4dfb-8d96-6ea634cbad49 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,984 | supabase-export-v2 | 3c6b22023d1d2cea | type :class:`int`, the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type :class:`float`. We will see more about numeric types later in the tutorial.
Division (``/``) always returns a float. To do :term:`floor division` and
get an integer result you can use the ``//`` operator; to calculate
the remainder you... | trusted_official_docs | CPython Docs | type :class:`int`, the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type :class:`float`. We will see more about numeric types later in the tutorial.
Division (``/``) always returns a float. To do :term:`floor division` and
get an integer result you can use the ``//`` operator; to calculate
the remainder you... | type :class:`int`, the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type :class:`float`. We will see more about numeric types later in the tutorial.
Division (``/``) always returns a float. To do :term:`floor division` and
get an integer result you can use the ``//`` operator; to calculate
the remainder you... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7f69ef4c-daef-4ae5-ba51-d4997c0effbb | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,067 | supabase-export-v2 | ee2dd60fd8811e8f | All slice operations return a new list containing the requested elements. This means that the following slice returns a :ref:`shallow copy <shallow_vs_deep_copy>` of the list::
>>> correct_rgba = rgba[:]
>>> correct_rgba[-1] = "Alpha"
>>> correct_rgba
["Red", "Green", "Blue", "Alpha"]
>>> rgba
["Red", "Green", "Bl... | trusted_official_docs | CPython Docs | All slice operations return a new list containing the requested elements. This means that the following slice returns a :ref:`shallow copy <shallow_vs_deep_copy>` of the list::
>>> correct_rgba = rgba[:]
>>> correct_rgba[-1] = "Alpha"
>>> correct_rgba
["Red", "Green", "Blue", "Alpha"]
>>> rgba
["Red", "Green", "Bl... | All slice operations return a new list containing the requested elements. This means that the following slice returns a :ref:`shallow copy <shallow_vs_deep_copy>` of the list::
>>> correct_rgba = rgba[:]
>>> correct_rgba[-1] = "Alpha"
>>> correct_rgba
["Red", "Green", "Blue", "Alpha"]
>>> rgba
["Red", "Green", "Bl... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
891f9a0a-8c09-4ad4-a6d4-57d68cfb0fc4 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,066 | supabase-export-v2 | 021c89c541d36562 | "Green", "Blue"] >>> rgba = rgb >>> id(rgb) == id(rgba) # they reference the same object True >>> rgba.append("Alph") >>> rgb ["Red", "Green", "Blue", "Alph"]
All slice operations return a new list containing the requested elements. This
means that the following slice returns a
:ref:`shallow copy <shallow_vs_deep_copy>... | trusted_official_docs | CPython Docs | "Green", "Blue"] >>> rgba = rgb >>> id(rgb) == id(rgba) # they reference the same object True >>> rgba.append("Alph") >>> rgb ["Red", "Green", "Blue", "Alph"]
All slice operations return a new list containing the requested elements. This
means that the following slice returns a
:ref:`shallow copy <shallow_vs_deep_copy>... | "Green", "Blue"] >>> rgba = rgb >>> id(rgb) == id(rgba) # they reference the same object True >>> rgba.append("Alph") >>> rgb ["Red", "Green", "Blue", "Alph"]
All slice operations return a new list containing the requested elements. This
means that the following slice returns a
:ref:`shallow copy <shallow_vs_deep_copy>... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8e7e2cf8-35d3-4543-91c4-954c7ac631e5 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,014 | supabase-export-v2 | 5e95beb0f6d7e58b | >>> # 3 times 'un', followed by 'ium' >>> 3 * 'un' + 'ium' 'unununium'
Two or more *string literals* (i.e. the ones enclosed between quotes) next
to each other are automatically concatenated. :: | trusted_official_docs | CPython Docs | >>> # 3 times 'un', followed by 'ium' >>> 3 * 'un' + 'ium' 'unununium'
Two or more *string literals* (i.e. the ones enclosed between quotes) next
to each other are automatically concatenated. :: | >>> # 3 times 'un', followed by 'ium' >>> 3 * 'un' + 'ium' 'unununium'
Two or more *string literals* (i.e. the ones enclosed between quotes) next
to each other are automatically concatenated. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
90013704-9c7a-4446-962a-abc99d6a4fb6 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,033 | supabase-export-v2 | bea6099e818c1ea9 | >>> word[:2] + word[2:] 'Python' >>> word[:4] + word[4:] 'Python'
One way to remember how slices work is to think of the indices as pointing
*between* characters, with the left edge 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:: | trusted_official_docs | CPython Docs | >>> word[:2] + word[2:] 'Python' >>> word[:4] + word[4:] 'Python'
One way to remember how slices work is to think of the indices as pointing
*between* characters, with the left edge 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:: | >>> word[:2] + word[2:] 'Python' >>> word[:4] + word[4:] 'Python'
One way to remember how slices work is to think of the indices as pointing
*between* characters, with the left edge 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:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
965b9994-50a2-4c70-a2fe-0b0e1ed6d20a | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,004 | supabase-export-v2 | 626ca80a5455cc59 | double quotes instead "doesn't" >>> '"Yes," they said.' '"Yes," they said.' >>> "\"Yes,\" they said." '"Yes," they said.' >>> '"Isn\'t," they said.' '"Isn\'t," they said.'
In the Python shell, the string definition and output string can look
different. The :func:`print` function produces a more readable output, by
omit... | trusted_official_docs | CPython Docs | double quotes instead "doesn't" >>> '"Yes," they said.' '"Yes," they said.' >>> "\"Yes,\" they said." '"Yes," they said.' >>> '"Isn\'t," they said.' '"Isn\'t," they said.'
In the Python shell, the string definition and output string can look
different. The :func:`print` function produces a more readable output, by
omit... | double quotes instead "doesn't" >>> '"Yes," they said.' '"Yes," they said.' >>> "\"Yes,\" they said." '"Yes," they said.' >>> '"Isn\'t," they said.' '"Isn\'t," they said.'
In the Python shell, the string definition and output string can look
different. The :func:`print` function produces a more readable output, by
omit... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9ce0ca82-b89a-47f6-8575-8ea9ec3b8a1d | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,080 | supabase-export-v2 | 7ce398934c12e432 | right-hand side are all evaluated first before any of the assignments take place. The right-hand side expressions are evaluated from the left to the right.
* The :keyword:`while` loop executes as long as the condition (here: ``a < 10``)
remains true. In Python, like in C, any non-zero integer value is true; zero is
f... | trusted_official_docs | CPython Docs | right-hand side are all evaluated first before any of the assignments take place. The right-hand side expressions are evaluated from the left to the right.
* The :keyword:`while` loop executes as long as the condition (here: ``a < 10``)
remains true. In Python, like in C, any non-zero integer value is true; zero is
f... | right-hand side are all evaluated first before any of the assignments take place. The right-hand side expressions are evaluated from the left to the right.
* The :keyword:`while` loop executes as long as the condition (here: ``a < 10``)
remains true. In Python, like in C, any non-zero integer value is true; zero is
f... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9daa9eea-cc9d-4a58-aab7-c9327875e45e | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,029 | supabase-export-v2 | a28ba8f49aea328a | >>> word[0:2] # characters from position 0 (included) to 2 (excluded) 'Py' >>> word[2:5] # characters from position 2 (included) to 5 (excluded) 'tho'
Slice indices have useful defaults; an omitted first index defaults to zero, an
omitted second index defaults to the size of the string being sliced. :: | trusted_official_docs | CPython Docs | >>> word[0:2] # characters from position 0 (included) to 2 (excluded) 'Py' >>> word[2:5] # characters from position 2 (included) to 5 (excluded) 'tho'
Slice indices have useful defaults; an omitted first index defaults to zero, an
omitted second index defaults to the size of the string being sliced. :: | >>> word[0:2] # characters from position 0 (included) to 2 (excluded) 'Py' >>> word[2:5] # characters from position 2 (included) to 5 (excluded) 'tho'
Slice indices have useful defaults; an omitted first index defaults to zero, an
omitted second index defaults to the size of the string being sliced. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9e2e273d-9112-4ad3-948d-096a61eb7e07 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,983 | supabase-export-v2 | 943c7e9e4a65a693 | 4 >>> 50 - 5*6 20 >>> (50 - 5*6) / 4 5.0 >>> 8 / 5 # division always returns a floating-point number 1.6
The integer numbers (e.g. ``2``, ``4``, ``20``) have type :class:`int`,
the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type
:class:`float`. We will see more about numeric types later in the tutorial. | trusted_official_docs | CPython Docs | 4 >>> 50 - 5*6 20 >>> (50 - 5*6) / 4 5.0 >>> 8 / 5 # division always returns a floating-point number 1.6
The integer numbers (e.g. ``2``, ``4``, ``20``) have type :class:`int`,
the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type
:class:`float`. We will see more about numeric types later in the tutorial. | 4 >>> 50 - 5*6 20 >>> (50 - 5*6) / 4 5.0 >>> 8 / 5 # division always returns a floating-point number 1.6
The integer numbers (e.g. ``2``, ``4``, ``20``) have type :class:`int`,
the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type
:class:`float`. We will see more about numeric types later in the tutorial. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9f1b3660-000e-4bfb-b448-7cc70826b9aa | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,076 | supabase-export-v2 | e4d640fd312dcf17 | First Steps Towards Programming ===============================
Of course, we can use Python for more complicated tasks than adding two and two
together. For instance, we can write an initial sub-sequence of the
`Fibonacci series <https://en.wikipedia.org/wiki/Fibonacci_sequence>`_
as follows:: | trusted_official_docs | CPython Docs | First Steps Towards Programming ===============================
Of course, we can use Python for more complicated tasks than adding two and two
together. For instance, we can write an initial sub-sequence of the
`Fibonacci series <https://en.wikipedia.org/wiki/Fibonacci_sequence>`_
as follows:: | First Steps Towards Programming ===============================
Of course, we can use Python for more complicated tasks than adding two and two
together. For instance, we can write an initial sub-sequence of the
`Fibonacci series <https://en.wikipedia.org/wiki/Fibonacci_sequence>`_
as follows:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9ff61235-368c-44d7-b7b4-189a3e668598 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,974 | supabase-export-v2 | e4d11d3ec3445492 | .. index:: single: # (hash); comment
Many of the examples in this manual, even those entered at the interactive
prompt, include comments. Comments in Python start with the hash character,
``#``, and extend to the end of the physical line. A comment may appear at the
start of a line or following whitespace or code, but ... | trusted_official_docs | CPython Docs | .. index:: single: # (hash); comment
Many of the examples in this manual, even those entered at the interactive
prompt, include comments. Comments in Python start with the hash character,
``#``, and extend to the end of the physical line. A comment may appear at the
start of a line or following whitespace or code, but ... | .. index:: single: # (hash); comment
Many of the examples in this manual, even those entered at the interactive
prompt, include comments. Comments in Python start with the hash character,
``#``, and extend to the end of the physical line. A comment may appear at the
start of a line or following whitespace or code, but ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a179f5fb-d817-4d64-9432-6ffa36fb321e | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,038 | supabase-export-v2 | aee699ec3c5cf7c1 | Attempting to use an index that is too large will result in an error::
>>> 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 | trusted_official_docs | CPython Docs | Attempting to use an index that is too large will result in an error::
>>> 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 | Attempting to use an index that is too large will result in an error::
>>> 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 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a21598b4-5d8f-4713-9c2c-7ce89c2c44dc | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,054 | supabase-export-v2 | 917acf0da6b88500 | Lists -----
Python knows a number of *compound* data types, used to group together other
values. The most versatile is the *list*, which can be written as a 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. :: | trusted_official_docs | CPython Docs | Lists -----
Python knows a number of *compound* data types, used to group together other
values. The most versatile is the *list*, which can be written as a 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. :: | Lists -----
Python knows a number of *compound* data types, used to group together other
values. The most versatile is the *list*, which can be written as a 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. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a248d7b4-8167-4129-a315-73837c24b90f | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,028 | supabase-export-v2 | 251d1612120b42d0 | In addition to indexing, *slicing* is also supported. While indexing is used to obtain individual characters, *slicing* allows you to obtain a substring::
>>> word[0:2] # characters from position 0 (included) to 2 (excluded)
'Py'
>>> word[2:5] # characters from position 2 (included) to 5 (excluded)
'tho' | trusted_official_docs | CPython Docs | In addition to indexing, *slicing* is also supported. While indexing is used to obtain individual characters, *slicing* allows you to obtain a substring::
>>> word[0:2] # characters from position 0 (included) to 2 (excluded)
'Py'
>>> word[2:5] # characters from position 2 (included) to 5 (excluded)
'tho' | In addition to indexing, *slicing* is also supported. While indexing is used to obtain individual characters, *slicing* allows you to obtain a substring::
>>> word[0:2] # characters from position 0 (included) to 2 (excluded)
'Py'
>>> word[2:5] # characters from position 2 (included) to 5 (excluded)
'tho' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a8112343-e49e-40bd-9b3c-cb615225cf06 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,024 | supabase-export-v2 | 661b4958f612a1a4 | >>> word = 'Python' >>> word[0] # character in position 0 'P' >>> word[5] # character in position 5 'n'
Indices may also be negative numbers, to start counting from the right:: | trusted_official_docs | CPython Docs | >>> word = 'Python' >>> word[0] # character in position 0 'P' >>> word[5] # character in position 5 'n'
Indices may also be negative numbers, to start counting from the right:: | >>> word = 'Python' >>> word[0] # character in position 0 'P' >>> word[5] # character in position 5 'n'
Indices may also be negative numbers, to start counting from the right:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a8b17cd6-59b8-494d-bc97-71d56fb7518c | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,078 | supabase-export-v2 | 1c9a1365c744423e | b = 0, 1 >>> while a < 10: ... print(a) ... a, b = b, a+b ... 0 1 1 2 3 5 8
This example introduces several new features. | trusted_official_docs | CPython Docs | b = 0, 1 >>> while a < 10: ... print(a) ... a, b = b, a+b ... 0 1 1 2 3 5 8
This example introduces several new features. | b = 0, 1 >>> while a < 10: ... print(a) ... a, b = b, a+b ... 0 1 1 2 3 5 8
This example introduces several new features. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aaab4d4e-2596-475c-b87a-0dce3725ec65 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,082 | supabase-export-v2 | bc902f810781ea0b | parser cannot guess when you have typed the last line). Note that each line within a basic block must be indented by the same amount.
* The :func:`print` function writes the value of the argument(s) it is given. It differs from just writing the expression you want to write (as we did
earlier in the calculator examples... | trusted_official_docs | CPython Docs | parser cannot guess when you have typed the last line). Note that each line within a basic block must be indented by the same amount.
* The :func:`print` function writes the value of the argument(s) it is given. It differs from just writing the expression you want to write (as we did
earlier in the calculator examples... | parser cannot guess when you have typed the last line). Note that each line within a basic block must be indented by the same amount.
* The :func:`print` function writes the value of the argument(s) it is given. It differs from just writing the expression you want to write (as we did
earlier in the calculator examples... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aac519be-82fe-4ec6-9dd3-788089f1f3b5 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,988 | supabase-export-v2 | 0367993d88408b66 | >>> 5 ** 2 # 5 squared 25 >>> 2 ** 7 # 2 to the power of 7 128
The equal sign (``=``) is used to assign a value to a variable. Afterwards, no
result is displayed before the next interactive prompt:: | trusted_official_docs | CPython Docs | >>> 5 ** 2 # 5 squared 25 >>> 2 ** 7 # 2 to the power of 7 128
The equal sign (``=``) is used to assign a value to a variable. Afterwards, no
result is displayed before the next interactive prompt:: | >>> 5 ** 2 # 5 squared 25 >>> 2 ** 7 # 2 to the power of 7 128
The equal sign (``=``) is used to assign a value to a variable. Afterwards, no
result is displayed before the next interactive prompt:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
aaf13c58-91de-49af-8d66-56923721ae84 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,999 | supabase-export-v2 | 58b5b5487eaa1811 | Text ----
Python can manipulate text (represented by type :class:`str`, so-called
"strings") as well as numbers. This includes characters "``!``", words
"``rabbit``", names "``Paris``", sentences "``Got your back.``", etc. "``Yay! :)``". They can be enclosed in single quotes (``'...'``) or double
quotes (``"..."``) wit... | trusted_official_docs | CPython Docs | Text ----
Python can manipulate text (represented by type :class:`str`, so-called
"strings") as well as numbers. This includes characters "``!``", words
"``rabbit``", names "``Paris``", sentences "``Got your back.``", etc. "``Yay! :)``". They can be enclosed in single quotes (``'...'``) or double
quotes (``"..."``) wit... | Text ----
Python can manipulate text (represented by type :class:`str`, so-called
"strings") as well as numbers. This includes characters "``!``", words
"``rabbit``", names "``Paris``", sentences "``Got your back.``", etc. "``Yay! :)``". They can be enclosed in single quotes (``'...'``) or double
quotes (``"..."``) wit... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ab453f46-91c1-43c6-a30b-88f35c8468c4 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,989 | supabase-export-v2 | abfad51e09b19faf | The equal sign (``=``) is used to assign a value to a variable. Afterwards, no result is displayed before the next interactive prompt::
>>> width = 20
>>> height = 5 * 9
>>> width * height
900 | trusted_official_docs | CPython Docs | The equal sign (``=``) is used to assign a value to a variable. Afterwards, no result is displayed before the next interactive prompt::
>>> width = 20
>>> height = 5 * 9
>>> width * height
900 | The equal sign (``=``) is used to assign a value to a variable. Afterwards, no result is displayed before the next interactive prompt::
>>> width = 20
>>> height = 5 * 9
>>> width * height
900 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b67c6a0d-111d-4cec-8e61-46fd578930d5 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,006 | supabase-export-v2 | 199774618b3963f7 | included in the string 'First line.\nSecond line.' >>> print(s) # with print(), special characters are interpreted, so \n produces new line First line. Second line.
If you don't want characters prefaced by ``\`` to be interpreted as
special characters, you can use *raw strings* by adding an ``r`` before
the first quote... | trusted_official_docs | CPython Docs | included in the string 'First line.\nSecond line.' >>> print(s) # with print(), special characters are interpreted, so \n produces new line First line. Second line.
If you don't want characters prefaced by ``\`` to be interpreted as
special characters, you can use *raw strings* by adding an ``r`` before
the first quote... | included in the string 'First line.\nSecond line.' >>> print(s) # with print(), special characters are interpreted, so \n produces new line First line. Second line.
If you don't want characters prefaced by ``\`` to be interpreted as
special characters, you can use *raw strings* by adding an ``r`` before
the first quote... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b7455114-ffee-4beb-a154-b4a1ee424f75 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,986 | supabase-export-v2 | d0103a9903aa065c | # the % operator returns the remainder of the division 2 >>> 5 * 3 + 2 # floored quotient * divisor + remainder 17
With Python, it is possible to use the ``**`` operator to calculate powers [#]_:: | trusted_official_docs | CPython Docs | # the % operator returns the remainder of the division 2 >>> 5 * 3 + 2 # floored quotient * divisor + remainder 17
With Python, it is possible to use the ``**`` operator to calculate powers [#]_:: | # the % operator returns the remainder of the division 2 >>> 5 * 3 + 2 # floored quotient * divisor + remainder 17
With Python, it is possible to use the ``**`` operator to calculate powers [#]_:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b8a7ba91-3edc-432c-868d-bb383d061427 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,972 | supabase-export-v2 | 65d9c5ca689cae39 | .. only:: html
You can use the "Copy" button (it appears in the upper-right 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. | trusted_official_docs | CPython Docs | .. only:: html
You can use the "Copy" button (it appears in the upper-right 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. | .. only:: html
You can use the "Copy" button (it appears in the upper-right 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. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b984b5b5-dd29-437c-9945-2ca6b0085b22 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,069 | supabase-export-v2 | be676c3059a13286 | Assignment to slices is also possible, and this can even change the size of the list or clear it entirely::
>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> letters
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> # replace some values
>>> letters[2:5] = ['C', 'D', 'E']
>>> letters
['a', 'b', 'C', 'D', 'E', 'f', 'g']... | trusted_official_docs | CPython Docs | Assignment to slices is also possible, and this can even change the size of the list or clear it entirely::
>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> letters
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> # replace some values
>>> letters[2:5] = ['C', 'D', 'E']
>>> letters
['a', 'b', 'C', 'D', 'E', 'f', 'g']... | Assignment to slices is also possible, and this can even change the size of the list or clear it entirely::
>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> letters
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> # replace some values
>>> letters[2:5] = ['C', 'D', 'E']
>>> letters
['a', 'b', 'C', 'D', 'E', 'f', 'g']... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bc97b3ca-5db6-4348-bc58-495d5b073220 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,084 | supabase-export-v2 | 717eeefabea5aca8 | >>> i = 256*256 >>> print('The value of i is', i) The value of i is 65536
The keyword argument *end* can be used to avoid the newline after the output,
or end the output with a different string:: | trusted_official_docs | CPython Docs | >>> i = 256*256 >>> print('The value of i is', i) The value of i is 65536
The keyword argument *end* can be used to avoid the newline after the output,
or end the output with a different string:: | >>> i = 256*256 >>> print('The value of i is', i) The value of i is 65536
The keyword argument *end* can be used to avoid the newline after the output,
or end the output with a different string:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bddd7da6-9da3-4231-9a9d-10ec88da478f | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,987 | supabase-export-v2 | be399b60619d9402 | With Python, it is possible to use the ``**`` operator to calculate powers [#]_::
>>> 5 ** 2 # 5 squared
25
>>> 2 ** 7 # 2 to the power of 7
128 | trusted_official_docs | CPython Docs | With Python, it is possible to use the ``**`` operator to calculate powers [#]_::
>>> 5 ** 2 # 5 squared
25
>>> 2 ** 7 # 2 to the power of 7
128 | With Python, it is possible to use the ``**`` operator to calculate powers [#]_::
>>> 5 ** 2 # 5 squared
25
>>> 2 ** 7 # 2 to the power of 7
128 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c15c4e11-2421-4dde-a866-f512ffa9bda9 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,005 | supabase-export-v2 | 6a2dc48a1fb50e0b | output string can look different. The :func:`print` function produces a more readable output, by omitting the enclosing quotes and by printing escaped and special characters::
>>> s = 'First line.\nSecond line.' # \n means newline
>>> s # without print(), special characters are included in the string
'First line.\nSe... | trusted_official_docs | CPython Docs | output string can look different. The :func:`print` function produces a more readable output, by omitting the enclosing quotes and by printing escaped and special characters::
>>> s = 'First line.\nSecond line.' # \n means newline
>>> s # without print(), special characters are included in the string
'First line.\nSe... | output string can look different. The :func:`print` function produces a more readable output, by omitting the enclosing quotes and by printing escaped and special characters::
>>> s = 'First line.\nSecond line.' # \n means newline
>>> s # without print(), special characters are included in the string
'First line.\nSe... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c9e86b2d-2bb8-438d-a067-5e6d62faf109 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,009 | supabase-export-v2 | a165bd85393d0d04 | raw strings: a raw string may not end in an odd number of ``\`` characters; see :ref:`the FAQ entry <faq-programming-raw-string-backslash>` for more information and workarounds.
String literals can span multiple lines. One way is using triple-quotes:
``"""..."""`` or ``'''...'''``. End-of-line characters are automatica... | trusted_official_docs | CPython Docs | raw strings: a raw string may not end in an odd number of ``\`` characters; see :ref:`the FAQ entry <faq-programming-raw-string-backslash>` for more information and workarounds.
String literals can span multiple lines. One way is using triple-quotes:
``"""..."""`` or ``'''...'''``. End-of-line characters are automatica... | raw strings: a raw string may not end in an odd number of ``\`` characters; see :ref:`the FAQ entry <faq-programming-raw-string-backslash>` for more information and workarounds.
String literals can span multiple lines. One way is using triple-quotes:
``"""..."""`` or ``'''...'''``. End-of-line characters are automatica... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cad8eb50-44fd-4778-9d4f-8d7138c2752c | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,077 | supabase-export-v2 | 1006a4e23863808a | for more complicated tasks than adding two and two together. For instance, we can write an initial sub-sequence of the `Fibonacci series <https://en.wikipedia.org/wiki/Fibonacci_sequence>`_ as follows::
>>> # Fibonacci series:
>>> # the sum of two elements defines the next
>>> a, b = 0, 1
>>> while a < 10:
... prin... | trusted_official_docs | CPython Docs | for more complicated tasks than adding two and two together. For instance, we can write an initial sub-sequence of the `Fibonacci series <https://en.wikipedia.org/wiki/Fibonacci_sequence>`_ as follows::
>>> # Fibonacci series:
>>> # the sum of two elements defines the next
>>> a, b = 0, 1
>>> while a < 10:
... prin... | for more complicated tasks than adding two and two together. For instance, we can write an initial sub-sequence of the `Fibonacci series <https://en.wikipedia.org/wiki/Fibonacci_sequence>`_ as follows::
>>> # Fibonacci series:
>>> # the sum of two elements defines the next
>>> a, b = 0, 1
>>> while a < 10:
... prin... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cb90a994-4f13-408c-97e3-ce79a32706b0 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,995 | supabase-export-v2 | 6d5eef0e58f251ff | to the variable ``_``. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example::
>>> tax = 12.5 / 100
>>> price = 100.50
>>> price * tax
12.5625
>>> price + _
113.0625
>>> round(_, 2)
113.06 | trusted_official_docs | CPython Docs | to the variable ``_``. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example::
>>> tax = 12.5 / 100
>>> price = 100.50
>>> price * tax
12.5625
>>> price + _
113.0625
>>> round(_, 2)
113.06 | to the variable ``_``. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example::
>>> tax = 12.5 / 100
>>> price = 100.50
>>> price * tax
12.5625
>>> price + _
113.0625
>>> round(_, 2)
113.06 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cdbe27e2-9aa8-496f-b62b-a66c63ebb2ec | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,060 | supabase-export-v2 | b3346441042bd0c1 | >>> squares + [36, 49, 64, 81, 100] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Unlike strings, which are :term:`immutable`, lists are a :term:`mutable`
type, i.e. it is possible to change their content:: | trusted_official_docs | CPython Docs | >>> squares + [36, 49, 64, 81, 100] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Unlike strings, which are :term:`immutable`, lists are a :term:`mutable`
type, i.e. it is possible to change their content:: | >>> squares + [36, 49, 64, 81, 100] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Unlike strings, which are :term:`immutable`, lists are a :term:`mutable`
type, i.e. it is possible to change their content:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d38b42aa-6174-49e0-ad85-336d54622131 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,043 | supabase-export-v2 | 8f0b90317c242db3 | item assignment >>> word[2:] = 'py' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment
If you need a different string, you should create a new one:: | trusted_official_docs | CPython Docs | item assignment >>> word[2:] = 'py' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment
If you need a different string, you should create a new one:: | item assignment >>> word[2:] = 'py' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment
If you need a different string, you should create a new one:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d63e98a1-cd66-44ca-b2c5-4a3339355509 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,001 | supabase-export-v2 | 5cc9d4c481f3042d | .. code-block:: pycon
>>> 'spam eggs' # single quotes
'spam eggs'
>>> "Paris rabbit got your back :)! Yay!" # double quotes
'Paris rabbit got your back :)! Yay!'
>>> '1975' # digits and numerals enclosed in quotes are also strings
'1975' | trusted_official_docs | CPython Docs | .. code-block:: pycon
>>> 'spam eggs' # single quotes
'spam eggs'
>>> "Paris rabbit got your back :)! Yay!" # double quotes
'Paris rabbit got your back :)! Yay!'
>>> '1975' # digits and numerals enclosed in quotes are also strings
'1975' | .. code-block:: pycon
>>> 'spam eggs' # single quotes
'spam eggs'
>>> "Paris rabbit got your back :)! Yay!" # double quotes
'Paris rabbit got your back :)! Yay!'
>>> '1975' # digits and numerals enclosed in quotes are also strings
'1975' | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d797f9ec-1795-4c54-b667-c1b1d0c4de68 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,002 | supabase-export-v2 | 7d201b4598834bf2 | :)! Yay!" # double quotes 'Paris rabbit got your back :)! Yay!' >>> '1975' # digits and numerals enclosed in quotes are also strings '1975'
To quote a quote, we need to "escape" it, by preceding it with ``\``. Alternatively, we can use the other type of quotation marks:: | trusted_official_docs | CPython Docs | :)! Yay!" # double quotes 'Paris rabbit got your back :)! Yay!' >>> '1975' # digits and numerals enclosed in quotes are also strings '1975'
To quote a quote, we need to "escape" it, by preceding it with ``\``. Alternatively, we can use the other type of quotation marks:: | :)! Yay!" # double quotes 'Paris rabbit got your back :)! Yay!' >>> '1975' # digits and numerals enclosed in quotes are also strings '1975'
To quote a quote, we need to "escape" it, by preceding it with ``\``. Alternatively, we can use the other type of quotation marks:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
de72fdce-e61c-4642-9a6d-01a4c8830063 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,036 | supabase-export-v2 | 18ebbbd1833c0bee | second row gives the corresponding negative indices. The slice from *i* to *j* consists of all characters between the edges labeled *i* and *j*, respectively.
For non-negative 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. | trusted_official_docs | CPython Docs | second row gives the corresponding negative indices. The slice from *i* to *j* consists of all characters between the edges labeled *i* and *j*, respectively.
For non-negative 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. | second row gives the corresponding negative indices. The slice from *i* to *j* consists of all characters between the edges labeled *i* and *j*, respectively.
For non-negative 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. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
de8ad2b7-4e21-4bc3-83cb-204979cf47c5 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,081 | supabase-export-v2 | 6fec19eedf29d696 | (less than), ``>`` (greater than), ``==`` (equal to), ``<=`` (less than or equal to), ``>=`` (greater than or equal to) and ``!=`` (not equal to).
* The *body* of the loop is *indented*: indentation is Python's way of grouping
statements. At the interactive prompt, you have to type a tab or space(s) for
each indented... | trusted_official_docs | CPython Docs | (less than), ``>`` (greater than), ``==`` (equal to), ``<=`` (less than or equal to), ``>=`` (greater than or equal to) and ``!=`` (not equal to).
* The *body* of the loop is *indented*: indentation is Python's way of grouping
statements. At the interactive prompt, you have to type a tab or space(s) for
each indented... | (less than), ``>`` (greater than), ``==`` (equal to), ``<=`` (less than or equal to), ``>=`` (greater than or equal to) and ``!=`` (not equal to).
* The *body* of the loop is *indented*: indentation is Python's way of grouping
statements. At the interactive prompt, you have to type a tab or space(s) for
each indented... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ea8e948a-9fea-4f74-bfa2-49835918116d | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,982 | supabase-export-v2 | 2ed4ded5f1fb10ad | syntax is straightforward: the operators ``+``, ``-``, ``*`` and ``/`` can be used to perform arithmetic; parentheses (``()``) can be used for grouping. For example::
>>> 2 + 2
4
>>> 50 - 5*6
20
>>> (50 - 5*6) / 4
5.0
>>> 8 / 5 # division always returns a floating-point number
1.6 | trusted_official_docs | CPython Docs | syntax is straightforward: the operators ``+``, ``-``, ``*`` and ``/`` can be used to perform arithmetic; parentheses (``()``) can be used for grouping. For example::
>>> 2 + 2
4
>>> 50 - 5*6
20
>>> (50 - 5*6) / 4
5.0
>>> 8 / 5 # division always returns a floating-point number
1.6 | syntax is straightforward: the operators ``+``, ``-``, ``*`` and ``/`` can be used to perform arithmetic; parentheses (``()``) can be used for grouping. For example::
>>> 2 + 2
4
>>> 50 - 5*6
20
>>> (50 - 5*6) / 4
5.0
>>> 8 / 5 # division always returns a floating-point number
1.6 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
eca73c3a-53f6-4ad7-ad41-1701fb086570 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,083 | supabase-export-v2 | 9be86bf41696189e | arguments, floating-point quantities, and strings. Strings are printed without quotes, and a space is inserted between items, so you can format things nicely, like this::
>>> i = 256*256
>>> print('The value of i is', i)
The value of i is 65536 | trusted_official_docs | CPython Docs | arguments, floating-point quantities, and strings. Strings are printed without quotes, and a space is inserted between items, so you can format things nicely, like this::
>>> i = 256*256
>>> print('The value of i is', i)
The value of i is 65536 | arguments, floating-point quantities, and strings. Strings are printed without quotes, and a space is inserted between items, so you can format things nicely, like this::
>>> i = 256*256
>>> print('The value of i is', i)
The value of i is 65536 | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ed1c552e-5ccc-4bfe-ac9a-8326c207b3ff | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,057 | supabase-export-v2 | eb32ab2ea2a78dd8 | Like strings (and all other built-in :term:`sequence` types), lists can be indexed and sliced::
>>> squares[0] # indexing returns the item
1
>>> squares[-1]
25
>>> squares[-3:] # slicing returns a new list
[9, 16, 25] | trusted_official_docs | CPython Docs | Like strings (and all other built-in :term:`sequence` types), lists can be indexed and sliced::
>>> squares[0] # indexing returns the item
1
>>> squares[-1]
25
>>> squares[-3:] # slicing returns a new list
[9, 16, 25] | Like strings (and all other built-in :term:`sequence` types), lists can be indexed and sliced::
>>> squares[0] # indexing returns the item
1
>>> squares[-1]
25
>>> squares[-3:] # slicing returns a new list
[9, 16, 25] | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ee612f86-ca3a-40ea-90f2-0fb5e1043fea | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,030 | supabase-export-v2 | 484633d952f205aa | indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced. ::
>>> word[:2] # character from the beginning to position 2 (excluded)
'Py'
>>> word[4:] # characters from position 4 (included) to the end
'on'
>>> word[-2:] # characters... | trusted_official_docs | CPython Docs | indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced. ::
>>> word[:2] # character from the beginning to position 2 (excluded)
'Py'
>>> word[4:] # characters from position 4 (included) to the end
'on'
>>> word[-2:] # characters... | indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced. ::
>>> word[:2] # character from the beginning to position 2 (excluded)
'Py'
>>> word[4:] # characters from position 4 (included) to the end
'on'
>>> word[-2:] # characters... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f3d75edf-1772-4a41-b3e2-27829ed4a645 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,992 | supabase-export-v2 | 53d30cda5eb15be7 | n # try to access an undefined variable Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'n' is not defined
There is full support for floating point; operators with mixed type operands
convert the integer operand to floating point:: | trusted_official_docs | CPython Docs | n # try to access an undefined variable Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'n' is not defined
There is full support for floating point; operators with mixed type operands
convert the integer operand to floating point:: | n # try to access an undefined variable Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'n' is not defined
There is full support for floating point; operators with mixed type operands
convert the integer operand to floating point:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f5599913-ecc8-4530-ad74-b832629e7ab9 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 52,991 | supabase-export-v2 | fe20fb1c208aff71 | If a variable is not "defined" (assigned a value), trying to use it will give you an error::
>>> n # try to access an undefined variable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined | trusted_official_docs | CPython Docs | If a variable is not "defined" (assigned a value), trying to use it will give you an error::
>>> n # try to access an undefined variable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined | If a variable is not "defined" (assigned a value), trying to use it will give you an error::
>>> n # try to access an undefined variable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fb172a9b-1276-441f-94dd-4a2e8b0c83d9 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,008 | supabase-export-v2 | 7749708a862aaf43 | >>> print('C:\this\name') # here \t means tab, \n means newline C: his ame >>> print(r'C:\this\name') # note the r before the quote C:\this\name
There is one subtle aspect to raw strings: a raw string may not end in
an odd number of ``\`` characters; see
:ref:`the FAQ entry <faq-programming-raw-string-backslash>` for m... | trusted_official_docs | CPython Docs | >>> print('C:\this\name') # here \t means tab, \n means newline C: his ame >>> print(r'C:\this\name') # note the r before the quote C:\this\name
There is one subtle aspect to raw strings: a raw string may not end in
an odd number of ``\`` characters; see
:ref:`the FAQ entry <faq-programming-raw-string-backslash>` for m... | >>> print('C:\this\name') # here \t means tab, \n means newline C: his ame >>> print(r'C:\this\name') # note the r before the quote C:\this\name
There is one subtle aspect to raw strings: a raw string may not end in
an odd number of ``\`` characters; see
:ref:`the FAQ entry <faq-programming-raw-string-backslash>` for m... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ff171fc4-5809-4e36-af7b-9cafb15c60c2 | CPython Docs | file://datasets/cpython/Doc/tutorial/introduction.rst | unknown | 283c4642-c975-4de3-af92-ac1ce0b3affc | 53,087 | supabase-export-v2 | 6c1fab1a43e8c7a5 | .. rubric:: Footnotes
.. [#] Since ``**`` has higher precedence than ``-``, ``-3**2`` will be
interpreted as ``-(3**2)`` and thus result in ``-9``. To avoid this
and get ``9``, you can use ``(-3)**2``. | trusted_official_docs | CPython Docs | .. rubric:: Footnotes
.. [#] Since ``**`` has higher precedence than ``-``, ``-3**2`` will be
interpreted as ``-(3**2)`` and thus result in ``-9``. To avoid this
and get ``9``, you can use ``(-3)**2``. | .. rubric:: Footnotes
.. [#] Since ``**`` has higher precedence than ``-``, ``-3**2`` will be
interpreted as ``-(3**2)`` and thus result in ``-9``. To avoid this
and get ``9``, you can use ``(-3)**2``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0c7ae4bc-3eb0-4340-864d-2d150461a963 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,130 | supabase-export-v2 | 574ce9a345218184 | of exact arithmetic is supported by the :mod:`fractions` module which implements arithmetic based on rational numbers (so the numbers like 1/3 can be represented exactly).
If you are a heavy user of floating-point operations you should take a look
at the NumPy package and many other packages for mathematical and
statis... | trusted_official_docs | CPython Docs | of exact arithmetic is supported by the :mod:`fractions` module which implements arithmetic based on rational numbers (so the numbers like 1/3 can be represented exactly).
If you are a heavy user of floating-point operations you should take a look
at the NumPy package and many other packages for mathematical and
statis... | of exact arithmetic is supported by the :mod:`fractions` module which implements arithmetic based on rational numbers (so the numbers like 1/3 can be represented exactly).
If you are a heavy user of floating-point operations you should take a look
at the NumPy package and many other packages for mathematical and
statis... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0e84919a-1e26-4f13-9618-e18a75eda7c6 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,119 | supabase-export-v2 | 54f52f4c46b3c28a | >>> round(0.1, 1) + round(0.1, 1) + round(0.1, 1) == round(0.3, 1) False
Though the numbers cannot be made closer to their intended exact values,
the :func:`math.isclose` function can be useful for comparing inexact values: | trusted_official_docs | CPython Docs | >>> round(0.1, 1) + round(0.1, 1) + round(0.1, 1) == round(0.3, 1) False
Though the numbers cannot be made closer to their intended exact values,
the :func:`math.isclose` function can be useful for comparing inexact values: | >>> round(0.1, 1) + round(0.1, 1) + round(0.1, 1) == round(0.3, 1) False
Though the numbers cannot be made closer to their intended exact values,
the :func:`math.isclose` function can be useful for comparing inexact values: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
100e14b0-ccda-40e2-9357-9e13c806e1ae | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,147 | supabase-export-v2 | 0722c73b789545ec | 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0 False >>> sum([0.1] * 10) == 1.0 True
The :func:`math.fsum` goes further and tracks all of the "lost digits"
as values are added onto a running total so that the result has only a
single rounding. This is slower than :func:`sum` but will be more
accurate in uncommon ... | trusted_official_docs | CPython Docs | 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0 False >>> sum([0.1] * 10) == 1.0 True
The :func:`math.fsum` goes further and tracks all of the "lost digits"
as values are added onto a running total so that the result has only a
single rounding. This is slower than :func:`sum` but will be more
accurate in uncommon ... | 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0 False >>> sum([0.1] * 10) == 1.0 True
The :func:`math.fsum` goes further and tracks all of the "lost digits"
as values are added onto a running total so that the result has only a
single rounding. This is slower than :func:`sum` but will be more
accurate in uncommon ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
135078f4-425b-4721-97ba-d0b7a85ede95 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,096 | supabase-export-v2 | 8ca6f829a7d7f027 | 0.333
and so on. No matter how many digits you're willing to write down, the result
will never be exactly 1/3, but will be an increasingly better approximation of
1/3. | trusted_official_docs | CPython Docs | 0.333
and so on. No matter how many digits you're willing to write down, the result
will never be exactly 1/3, but will be an increasingly better approximation of
1/3. | 0.333
and so on. No matter how many digits you're willing to write down, the result
will never be exactly 1/3, but will be an increasingly better approximation of
1/3. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1496320b-4d9d-4ad0-a885-ccca31640668 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,143 | supabase-export-v2 | 410432443b3aaf3b | >>> x == float.fromhex('0x1.921f9f01b866ep+1') True
Since the representation is exact, it is useful for reliably porting values
across different versions of Python (platform independence) and exchanging
data with other languages that support the same format (such as Java and C99). | trusted_official_docs | CPython Docs | >>> x == float.fromhex('0x1.921f9f01b866ep+1') True
Since the representation is exact, it is useful for reliably porting values
across different versions of Python (platform independence) and exchanging
data with other languages that support the same format (such as Java and C99). | >>> x == float.fromhex('0x1.921f9f01b866ep+1') True
Since the representation is exact, it is useful for reliably porting values
across different versions of Python (platform independence) and exchanging
data with other languages that support the same format (such as Java and C99). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
204adbb6-11e1-4bf0-b1fd-e7e58581631c | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,125 | supabase-export-v2 | 6972bbfae07bf6da | >>> round(math.pi, ndigits=2) == round(22 / 7, ndigits=2) True
Binary floating-point arithmetic holds many surprises like this. The problem
with "0.1" is explained in precise detail below, in the "Representation Error"
section. See `Examples of Floating Point Problems
<https://jvns.ca/blog/2023/01/13/examples-of-floati... | trusted_official_docs | CPython Docs | >>> round(math.pi, ndigits=2) == round(22 / 7, ndigits=2) True
Binary floating-point arithmetic holds many surprises like this. The problem
with "0.1" is explained in precise detail below, in the "Representation Error"
section. See `Examples of Floating Point Problems
<https://jvns.ca/blog/2023/01/13/examples-of-floati... | >>> round(math.pi, ndigits=2) == round(22 / 7, ndigits=2) True
Binary floating-point arithmetic holds many surprises like this. The problem
with "0.1" is explained in precise detail below, in the "Representation Error"
section. See `Examples of Floating Point Problems
<https://jvns.ca/blog/2023/01/13/examples-of-floati... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2200e1c2-6635-4b1e-83a8-b3b91c6b27e7 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,116 | supabase-export-v2 | c652e5d21a1c9452 | >>> 0.1 + 0.1 + 0.1 == 0.3 False
Also, since the 0.1 cannot get any closer to the exact value of 1/10 and
0.3 cannot get any closer to the exact value of 3/10, then pre-rounding with
:func:`round` function cannot help: | trusted_official_docs | CPython Docs | >>> 0.1 + 0.1 + 0.1 == 0.3 False
Also, since the 0.1 cannot get any closer to the exact value of 1/10 and
0.3 cannot get any closer to the exact value of 3/10, then pre-rounding with
:func:`round` function cannot help: | >>> 0.1 + 0.1 + 0.1 == 0.3 False
Also, since the 0.1 cannot get any closer to the exact value of 1/10 and
0.3 cannot get any closer to the exact value of 3/10, then pre-rounding with
:func:`round` function cannot help: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
25993fb5-38be-4f03-beeb-b6ac14c1c20c | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,131 | supabase-export-v2 | f1e113fa96e27ad1 | you should take a look at the NumPy package and many other packages for mathematical and statistical operations supplied by the SciPy project. See <https://scipy.org>.
Python provides tools that may help on those rare occasions when you really
*do* want to know the exact value of a float. The
:meth:`float.as_integer_ra... | trusted_official_docs | CPython Docs | you should take a look at the NumPy package and many other packages for mathematical and statistical operations supplied by the SciPy project. See <https://scipy.org>.
Python provides tools that may help on those rare occasions when you really
*do* want to know the exact value of a float. The
:meth:`float.as_integer_ra... | you should take a look at the NumPy package and many other packages for mathematical and statistical operations supplied by the SciPy project. See <https://scipy.org>.
Python provides tools that may help on those rare occasions when you really
*do* want to know the exact value of a float. The
:meth:`float.as_integer_ra... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
28963fce-d3c3-41b5-8a96-6e4e1dd884c8 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,114 | supabase-export-v2 | 1bfebbfc24a3fdb8 | It's important to realize that this is, in a real sense, an illusion: you're simply rounding the *display* of the true machine value.
One illusion may beget another. For example, since 0.1 is not exactly 1/10,
summing three values of 0.1 may not yield exactly 0.3, either: | trusted_official_docs | CPython Docs | It's important to realize that this is, in a real sense, an illusion: you're simply rounding the *display* of the true machine value.
One illusion may beget another. For example, since 0.1 is not exactly 1/10,
summing three values of 0.1 may not yield exactly 0.3, either: | It's important to realize that this is, in a real sense, an illusion: you're simply rounding the *display* of the true machine value.
One illusion may beget another. For example, since 0.1 is not exactly 1/10,
summing three values of 0.1 may not yield exactly 0.3, either: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2ba62077-066a-4201-ad7d-a8329e1010af | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,126 | supabase-export-v2 | 195b2062302123d3 | the kinds of problems commonly encountered in practice. Also see `The Perils of Floating Point <http://www.indowsway.com/floatingpoint.htm>`_ for a more complete account of other common surprises.
As that says near the end, "there are no easy answers." Still, don't be unduly
wary of floating point! The errors in Python... | trusted_official_docs | CPython Docs | the kinds of problems commonly encountered in practice. Also see `The Perils of Floating Point <http://www.indowsway.com/floatingpoint.htm>`_ for a more complete account of other common surprises.
As that says near the end, "there are no easy answers." Still, don't be unduly
wary of floating point! The errors in Python... | the kinds of problems commonly encountered in practice. Also see `The Perils of Floating Point <http://www.indowsway.com/floatingpoint.htm>`_ for a more complete account of other common surprises.
As that says near the end, "there are no easy answers." Still, don't be unduly
wary of floating point! The errors in Python... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3042f75c-1fd3-4763-a260-19503f5636e8 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,107 | supabase-export-v2 | d0ad69f7f3f1903f | 17 significant digits, ``0.10000000000000001``. Starting with Python 3.1, Python (on most systems) is now able to choose the shortest of these and simply display ``0.1``.
Note that this is in the very nature of binary floating point: this is not a bug
in Python, and it is not a bug in your code either. You'll see the s... | trusted_official_docs | CPython Docs | 17 significant digits, ``0.10000000000000001``. Starting with Python 3.1, Python (on most systems) is now able to choose the shortest of these and simply display ``0.1``.
Note that this is in the very nature of binary floating point: this is not a bug
in Python, and it is not a bug in your code either. You'll see the s... | 17 significant digits, ``0.10000000000000001``. Starting with Python 3.1, Python (on most systems) is now able to choose the shortest of these and simply display ``0.1``.
Note that this is in the very nature of binary floating point: this is not a bug
in Python, and it is not a bug in your code either. You'll see the s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
355009c3-2de8-4c46-9869-c7e3d8de0f12 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,129 | supabase-export-v2 | c7f2978c9b07b7cf | For use cases which require exact decimal representation, try using the :mod:`decimal` module which implements decimal arithmetic suitable for accounting applications and high-precision applications.
Another form of exact arithmetic is supported by the :mod:`fractions` module
which implements arithmetic based on ration... | trusted_official_docs | CPython Docs | For use cases which require exact decimal representation, try using the :mod:`decimal` module which implements decimal arithmetic suitable for accounting applications and high-precision applications.
Another form of exact arithmetic is supported by the :mod:`fractions` module
which implements arithmetic based on ration... | For use cases which require exact decimal representation, try using the :mod:`decimal` module which implements decimal arithmetic suitable for accounting applications and high-precision applications.
Another form of exact arithmetic is supported by the :mod:`fractions` module
which implements arithmetic based on ration... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3a16b594-bbb0-4b93-b3a8-596154ef2ced | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,168 | supabase-export-v2 | 7fa3a8089ade0d1c | 3602879701896397 / 2 ** 55
Note that since we rounded up, this is actually a little bit larger than 1/10;
if we had not rounded up, the quotient would have been a little bit smaller than
1/10. But in no case can it be *exactly* 1/10! | trusted_official_docs | CPython Docs | 3602879701896397 / 2 ** 55
Note that since we rounded up, this is actually a little bit larger than 1/10;
if we had not rounded up, the quotient would have been a little bit smaller than
1/10. But in no case can it be *exactly* 1/10! | 3602879701896397 / 2 ** 55
Note that since we rounded up, this is actually a little bit larger than 1/10;
if we had not rounded up, the quotient would have been a little bit smaller than
1/10. But in no case can it be *exactly* 1/10! | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3a6f344e-7e9a-4939-be72-ef84be0f6ac9 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,093 | supabase-export-v2 | 57568828aac2cdae | fractions have identical values, the only real difference being that the first is written in base 10 fractional notation, and the second in base 2.
Unfortunately, most decimal fractions cannot be represented exactly as binary
fractions. A consequence is that, in general, the decimal floating-point
numbers you enter are... | trusted_official_docs | CPython Docs | fractions have identical values, the only real difference being that the first is written in base 10 fractional notation, and the second in base 2.
Unfortunately, most decimal fractions cannot be represented exactly as binary
fractions. A consequence is that, in general, the decimal floating-point
numbers you enter are... | fractions have identical values, the only real difference being that the first is written in base 10 fractional notation, and the second in base 2.
Unfortunately, most decimal fractions cannot be represented exactly as binary
fractions. A consequence is that, in general, the decimal floating-point
numbers you enter are... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
55967b68-71d2-40a2-8733-834b4429d854 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,159 | supabase-export-v2 | 7094be0cb8a028a4 | >>> 2**52 <= 2**56 // 10 < 2**53 True
That is, 56 is the only value for *N* that leaves *J* with exactly 53 bits. The
best possible value for *J* is then that quotient rounded: | trusted_official_docs | CPython Docs | >>> 2**52 <= 2**56 // 10 < 2**53 True
That is, 56 is the only value for *N* that leaves *J* with exactly 53 bits. The
best possible value for *J* is then that quotient rounded: | >>> 2**52 <= 2**56 // 10 < 2**53 True
That is, 56 is the only value for *N* that leaves *J* with exactly 53 bits. The
best possible value for *J* is then that quotient rounded: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5a2b61ef-1b77-4a81-b446-3e107e924c8d | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,092 | supabase-export-v2 | 8cd2f7f1776dcb3f | ************************************************** Floating-Point Arithmetic: Issues and Limitations **************************************************
Floating-point numbers are represented in computer hardware as base 2 (binary)
fractions. For example, the **decimal** fraction ``0.625``
has value 6/10 + 2/100 + 5/100... | trusted_official_docs | CPython Docs | ************************************************** Floating-Point Arithmetic: Issues and Limitations **************************************************
Floating-point numbers are represented in computer hardware as base 2 (binary)
fractions. For example, the **decimal** fraction ``0.625``
has value 6/10 + 2/100 + 5/100... | ************************************************** Floating-Point Arithmetic: Issues and Limitations **************************************************
Floating-point numbers are represented in computer hardware as base 2 (binary)
fractions. For example, the **decimal** fraction ``0.625``
has value 6/10 + 2/100 + 5/100... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6698a730-1c97-42fd-9541-7066d23ae313 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,175 | supabase-export-v2 | 15b090093764d71a | >>> 3602879701896397 * 10 ** 55 // 2 ** 55 1000000000000000055511151231257827021181583404541015625
meaning that the exact number stored in the computer is equal to
the decimal value 0.1000000000000000055511151231257827021181583404541015625. Instead of displaying the full decimal value, many languages (including
older v... | trusted_official_docs | CPython Docs | >>> 3602879701896397 * 10 ** 55 // 2 ** 55 1000000000000000055511151231257827021181583404541015625
meaning that the exact number stored in the computer is equal to
the decimal value 0.1000000000000000055511151231257827021181583404541015625. Instead of displaying the full decimal value, many languages (including
older v... | >>> 3602879701896397 * 10 ** 55 // 2 ** 55 1000000000000000055511151231257827021181583404541015625
meaning that the exact number stored in the computer is equal to
the decimal value 0.1000000000000000055511151231257827021181583404541015625. Instead of displaying the full decimal value, many languages (including
older v... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6c3b84ba-6a17-4cba-a45b-34b14afd10e8 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,108 | supabase-export-v2 | dbb0498d3c7c97c2 | thing in all languages that support your hardware's floating-point arithmetic (although some languages may not *display* the difference by default, or in all output modes).
For more pleasant output, you may wish to use string formatting to produce a
limited number of significant digits: | trusted_official_docs | CPython Docs | thing in all languages that support your hardware's floating-point arithmetic (although some languages may not *display* the difference by default, or in all output modes).
For more pleasant output, you may wish to use string formatting to produce a
limited number of significant digits: | thing in all languages that support your hardware's floating-point arithmetic (although some languages may not *display* the difference by default, or in all output modes).
For more pleasant output, you may wish to use string formatting to produce a
limited number of significant digits: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
74f55781-140c-4174-a26b-76a00937b1e5 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,154 | supabase-export-v2 | 7eadcf082ef2bc5b | This is the chief reason why Python (or Perl, C, C++, Java, Fortran, and many others) often won't display the exact decimal number you expect.
Why is that? 1/10 is not exactly representable as a binary fraction. Since at
least 2000, almost all machines use IEEE 754 binary floating-point arithmetic,
and almost all platf... | trusted_official_docs | CPython Docs | This is the chief reason why Python (or Perl, C, C++, Java, Fortran, and many others) often won't display the exact decimal number you expect.
Why is that? 1/10 is not exactly representable as a binary fraction. Since at
least 2000, almost all machines use IEEE 754 binary floating-point arithmetic,
and almost all platf... | This is the chief reason why Python (or Perl, C, C++, Java, Fortran, and many others) often won't display the exact decimal number you expect.
Why is that? 1/10 is not exactly representable as a binary fraction. Since at
least 2000, almost all machines use IEEE 754 binary floating-point arithmetic,
and almost all platf... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
80bff80c-e75b-4529-ae31-41b59f320590 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,149 | supabase-export-v2 | c27d2338d9f67349 | .. doctest::
>>> arr = [-0.10430216751806065, -266310978.67179024, 143401161448607.16,
... -143401161400469.7, 266262841.31058735, -0.003244936839808227]
>>> float(sum(map(Fraction, arr))) # Exact summation with single rounding
8.042173697819788e-13
>>> math.fsum(arr) # Single rounding
8.042173697819788e-13
>>> s... | trusted_official_docs | CPython Docs | .. doctest::
>>> arr = [-0.10430216751806065, -266310978.67179024, 143401161448607.16,
... -143401161400469.7, 266262841.31058735, -0.003244936839808227]
>>> float(sum(map(Fraction, arr))) # Exact summation with single rounding
8.042173697819788e-13
>>> math.fsum(arr) # Single rounding
8.042173697819788e-13
>>> s... | .. doctest::
>>> arr = [-0.10430216751806065, -266310978.67179024, 143401161448607.16,
... -143401161400469.7, 266262841.31058735, -0.003244936839808227]
>>> float(sum(map(Fraction, arr))) # Exact summation with single rounding
8.042173697819788e-13
>>> math.fsum(arr) # Single rounding
8.042173697819788e-13
>>> s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
86d3bfa8-640e-45a0-80d8-fd05c75a5319 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,094 | supabase-export-v2 | 8a3a4760362adc77 | A consequence is that, in general, the decimal floating-point numbers you enter are only approximated by the binary floating-point numbers actually stored in the machine.
The problem is easier to understand at first in base 10. Consider the fraction
1/3. You can approximate that as a base 10 fraction:: | trusted_official_docs | CPython Docs | A consequence is that, in general, the decimal floating-point numbers you enter are only approximated by the binary floating-point numbers actually stored in the machine.
The problem is easier to understand at first in base 10. Consider the fraction
1/3. You can approximate that as a base 10 fraction:: | A consequence is that, in general, the decimal floating-point numbers you enter are only approximated by the binary floating-point numbers actually stored in the machine.
The problem is easier to understand at first in base 10. Consider the fraction
1/3. You can approximate that as a base 10 fraction:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
87a31110-daf2-4360-acef-6b682d872164 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,144 | supabase-export-v2 | 6c8762434c715457 | porting values across different versions of Python (platform independence) and exchanging data with other languages that support the same format (such as Java and C99).
Another helpful tool is the :func:`sum` function which helps mitigate
loss-of-precision during summation. It uses extended precision for
intermediate r... | trusted_official_docs | CPython Docs | porting values across different versions of Python (platform independence) and exchanging data with other languages that support the same format (such as Java and C99).
Another helpful tool is the :func:`sum` function which helps mitigate
loss-of-precision during summation. It uses extended precision for
intermediate r... | porting values across different versions of Python (platform independence) and exchanging data with other languages that support the same format (such as Java and C99).
Another helpful tool is the :func:`sum` function which helps mitigate
loss-of-precision during summation. It uses extended precision for
intermediate r... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8f4fb5b8-2b8c-4157-80ce-ebfc4b6827d1 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,155 | supabase-export-v2 | aecfc783b8753927 | to convert 0.1 to the closest fraction it can of the form *J*/2**\ *N* where *J* is an integer containing exactly 53 bits. Rewriting ::
1 / 10 ~= J / (2**N) | trusted_official_docs | CPython Docs | to convert 0.1 to the closest fraction it can of the form *J*/2**\ *N* where *J* is an integer containing exactly 53 bits. Rewriting ::
1 / 10 ~= J / (2**N) | to convert 0.1 to the closest fraction it can of the form *J*/2**\ *N* where *J* is an integer containing exactly 53 bits. Rewriting ::
1 / 10 ~= J / (2**N) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8fd3a184-3163-44e3-90d0-0f78b37c02ed | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,127 | supabase-export-v2 | 6cb31dcee738396d | tasks, but you do need to keep in mind that it's not decimal arithmetic and that every float operation can suffer a new rounding error.
While pathological cases do exist, for most casual use of floating-point
arithmetic you'll see the result you expect in the end if you simply round the
display of your final results to... | trusted_official_docs | CPython Docs | tasks, but you do need to keep in mind that it's not decimal arithmetic and that every float operation can suffer a new rounding error.
While pathological cases do exist, for most casual use of floating-point
arithmetic you'll see the result you expect in the end if you simply round the
display of your final results to... | tasks, but you do need to keep in mind that it's not decimal arithmetic and that every float operation can suffer a new rounding error.
While pathological cases do exist, for most casual use of floating-point
arithmetic you'll see the result you expect in the end if you simply round the
display of your final results to... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
904f7f09-d095-4fee-987a-b71a018f10cb | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,099 | supabase-export-v2 | a66bd49ee0ab1314 | 0.0001100110011001100110011001100110011001100110011...
Stop at any finite number of bits, and you get an approximation. On most
machines today, floats are approximated using a binary fraction with
the numerator using the first 53 bits starting with the most significant bit and
with the denominator as a power of two. In... | trusted_official_docs | CPython Docs | 0.0001100110011001100110011001100110011001100110011...
Stop at any finite number of bits, and you get an approximation. On most
machines today, floats are approximated using a binary fraction with
the numerator using the first 53 bits starting with the most significant bit and
with the denominator as a power of two. In... | 0.0001100110011001100110011001100110011001100110011...
Stop at any finite number of bits, and you get an approximation. On most
machines today, floats are approximated using a binary fraction with
the numerator using the first 53 bits starting with the most significant bit and
with the denominator as a power of two. In... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
90c8d9a5-0d06-4fff-8db6-89d11ba492d0 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,146 | supabase-export-v2 | 80cc37b9f7921a9b | .. doctest::
>>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0
False
>>> sum([0.1] * 10) == 1.0
True | trusted_official_docs | CPython Docs | .. doctest::
>>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0
False
>>> sum([0.1] * 10) == 1.0
True | .. doctest::
>>> 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1.0
False
>>> sum([0.1] * 10) == 1.0
True | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a482e6d6-8c4d-4b82-8e13-8fbab847a968 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,105 | supabase-export-v2 | 587615dfc85df82a | Just remember, even though the printed result looks like the exact value of 1/10, the actual stored value is the nearest representable binary fraction.
Interestingly, there are many different decimal numbers that share the same
nearest approximate binary fraction. For example, the numbers ``0.1`` and
``0.10000000000000... | trusted_official_docs | CPython Docs | Just remember, even though the printed result looks like the exact value of 1/10, the actual stored value is the nearest representable binary fraction.
Interestingly, there are many different decimal numbers that share the same
nearest approximate binary fraction. For example, the numbers ``0.1`` and
``0.10000000000000... | Just remember, even though the printed result looks like the exact value of 1/10, the actual stored value is the nearest representable binary fraction.
Interestingly, there are many different decimal numbers that share the same
nearest approximate binary fraction. For example, the numbers ``0.1`` and
``0.10000000000000... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b2a87fbb-6c00-4c6e-89ff-f3a1a053ca5f | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,169 | supabase-export-v2 | 937df931ec9d405a | we had not rounded up, the quotient would have been a little bit smaller than 1/10. But in no case can it be *exactly* 1/10!
So the computer never "sees" 1/10: what it sees is the exact fraction given
above, the best IEEE 754 double approximation it can get: | trusted_official_docs | CPython Docs | we had not rounded up, the quotient would have been a little bit smaller than 1/10. But in no case can it be *exactly* 1/10!
So the computer never "sees" 1/10: what it sees is the exact fraction given
above, the best IEEE 754 double approximation it can get: | we had not rounded up, the quotient would have been a little bit smaller than 1/10. But in no case can it be *exactly* 1/10!
So the computer never "sees" 1/10: what it sees is the exact fraction given
above, the best IEEE 754 double approximation it can get: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b615eaa0-967e-4182-b8d2-41b90dcef8fe | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,153 | supabase-export-v2 | 181a2661401394c6 | example in detail, and shows how you can perform an exact analysis of cases like this yourself. Basic familiarity with binary floating-point representation is assumed.
:dfn:`Representation error` refers to the fact that some (most, actually)
decimal fractions cannot be represented exactly as binary (base 2) fractions. ... | trusted_official_docs | CPython Docs | example in detail, and shows how you can perform an exact analysis of cases like this yourself. Basic familiarity with binary floating-point representation is assumed.
:dfn:`Representation error` refers to the fact that some (most, actually)
decimal fractions cannot be represented exactly as binary (base 2) fractions. ... | example in detail, and shows how you can perform an exact analysis of cases like this yourself. Basic familiarity with binary floating-point representation is assumed.
:dfn:`Representation error` refers to the fact that some (most, actually)
decimal fractions cannot be represented exactly as binary (base 2) fractions. ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d3955f32-b542-4a52-b41d-e293795bcf72 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,128 | supabase-export-v2 | 5838182630d25bab | final results to the number of decimal digits you expect. :func:`str` usually suffices, and for finer control see the :meth:`str.format` method's format specifiers in :ref:`formatstrings`.
For use cases which require exact decimal representation, try using the
:mod:`decimal` module which implements decimal arithmetic s... | trusted_official_docs | CPython Docs | final results to the number of decimal digits you expect. :func:`str` usually suffices, and for finer control see the :meth:`str.format` method's format specifiers in :ref:`formatstrings`.
For use cases which require exact decimal representation, try using the
:mod:`decimal` module which implements decimal arithmetic s... | final results to the number of decimal digits you expect. :func:`str` usually suffices, and for finer control see the :meth:`str.format` method's format specifiers in :ref:`formatstrings`.
For use cases which require exact decimal representation, try using the
:mod:`decimal` module which implements decimal arithmetic s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d61662b6-2a05-43a1-8bd5-3e74dfec2b19 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,106 | supabase-export-v2 | 77172b718b93b9ec | Since all of these decimal values share the same approximation, any one of them could be displayed while still preserving the invariant ``eval(repr(x)) == x``.
Historically, the Python prompt and built-in :func:`repr` function would choose
the one with 17 significant digits, ``0.10000000000000001``. Starting with
Pytho... | trusted_official_docs | CPython Docs | Since all of these decimal values share the same approximation, any one of them could be displayed while still preserving the invariant ``eval(repr(x)) == x``.
Historically, the Python prompt and built-in :func:`repr` function would choose
the one with 17 significant digits, ``0.10000000000000001``. Starting with
Pytho... | Since all of these decimal values share the same approximation, any one of them could be displayed while still preserving the invariant ``eval(repr(x)) == x``.
Historically, the Python prompt and built-in :func:`repr` function would choose
the one with 17 significant digits, ``0.10000000000000001``. Starting with
Pytho... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e51f6983-8eb1-49fc-81be-f6749fa3e6ff | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,100 | supabase-export-v2 | 51ff2722f9f946b3 | of 1/10, the binary fraction is ``3602879701896397 / 2 ** 55`` which is close to but not exactly equal to the true value of 1/10.
Many users are not aware of the approximation because of the way values are
displayed. Python only prints a decimal approximation to the true decimal
value of the binary approximation stored... | trusted_official_docs | CPython Docs | of 1/10, the binary fraction is ``3602879701896397 / 2 ** 55`` which is close to but not exactly equal to the true value of 1/10.
Many users are not aware of the approximation because of the way values are
displayed. Python only prints a decimal approximation to the true decimal
value of the binary approximation stored... | of 1/10, the binary fraction is ``3602879701896397 / 2 ** 55`` which is close to but not exactly equal to the true value of 1/10.
Many users are not aware of the approximation because of the way values are
displayed. Python only prints a decimal approximation to the true decimal
value of the binary approximation stored... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e5ea4aa1-b8ca-4007-80a1-06f59f3b523a | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,097 | supabase-export-v2 | fab62828da611d1e | matter how many digits you're willing to write down, the result will never be exactly 1/3, but will be an increasingly better approximation of 1/3.
In the same way, no matter how many base 2 digits you're willing to use, the
decimal value 0.1 cannot be represented exactly as a base 2 fraction. In base
2, 1/10 is the in... | trusted_official_docs | CPython Docs | matter how many digits you're willing to write down, the result will never be exactly 1/3, but will be an increasingly better approximation of 1/3.
In the same way, no matter how many base 2 digits you're willing to use, the
decimal value 0.1 cannot be represented exactly as a base 2 fraction. In base
2, 1/10 is the in... | matter how many digits you're willing to write down, the result will never be exactly 1/3, but will be an increasingly better approximation of 1/3.
In the same way, no matter how many base 2 digits you're willing to use, the
decimal value 0.1 cannot be represented exactly as a base 2 fraction. In base
2, 1/10 is the in... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fae0bf29-86ed-4a49-8ce2-776501fe74e2 | CPython Docs | file://datasets/cpython/Doc/tutorial/floatingpoint.rst | unknown | ddde9da2-0379-4f66-8df1-920a540a6e16 | 53,152 | supabase-export-v2 | 99039587334a1df7 | Representation Error ====================
This section explains the "0.1" example in detail, and shows how you can perform
an exact analysis of cases like this yourself. Basic familiarity with binary
floating-point representation is assumed. | trusted_official_docs | CPython Docs | Representation Error ====================
This section explains the "0.1" example in detail, and shows how you can perform
an exact analysis of cases like this yourself. Basic familiarity with binary
floating-point representation is assumed. | Representation Error ====================
This section explains the "0.1" example in detail, and shows how you can perform
an exact analysis of cases like this yourself. Basic familiarity with binary
floating-point representation is assumed. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
03010013-2aea-4ba5-96a4-f1d126dab0b4 | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,232 | supabase-export-v2 | 8cbd8019e8410818 | modules for accessing the internet and processing internet protocols. Two of the simplest are :mod:`urllib.request` for retrieving data from URLs and :mod:`smtplib` for sending mail::
>>> from urllib.request import urlopen
>>> with urlopen('https://docs.python.org/3/') as response:
... for line in response:
... line... | trusted_official_docs | CPython Docs | modules for accessing the internet and processing internet protocols. Two of the simplest are :mod:`urllib.request` for retrieving data from URLs and :mod:`smtplib` for sending mail::
>>> from urllib.request import urlopen
>>> with urlopen('https://docs.python.org/3/') as response:
... for line in response:
... line... | modules for accessing the internet and processing internet protocols. Two of the simplest are :mod:`urllib.request` for retrieving data from URLs and :mod:`smtplib` for sending mail::
>>> from urllib.request import urlopen
>>> with urlopen('https://docs.python.org/3/') as response:
... for line in response:
... line... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
055fa32b-d653-497a-99c6-492c4cf96ddc | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,238 | supabase-export-v2 | 2a7fbc81b63f225d | the focus of the implementation is on efficient member extraction for output formatting and manipulation. The module also supports objects that are timezone aware. ::
>>> # dates are easily constructed and formatted
>>> import datetime as dt
>>> now = dt.date.today()
>>> now
datetime.date(2003, 12, 2)
>>> now.strf... | trusted_official_docs | CPython Docs | the focus of the implementation is on efficient member extraction for output formatting and manipulation. The module also supports objects that are timezone aware. ::
>>> # dates are easily constructed and formatted
>>> import datetime as dt
>>> now = dt.date.today()
>>> now
datetime.date(2003, 12, 2)
>>> now.strf... | the focus of the implementation is on efficient member extraction for output formatting and manipulation. The module also supports objects that are timezone aware. ::
>>> # dates are easily constructed and formatted
>>> import datetime as dt
>>> now = dt.date.today()
>>> now
datetime.date(2003, 12, 2)
>>> now.strf... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0d87546b-70d3-4087-9295-17655612e912 | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,266 | supabase-export-v2 | 6d336cd87d881753 | :mod:`xmlrpc.server` modules make implementing remote procedure calls into an almost trivial task. Despite the modules' names, no direct knowledge or handling of XML is needed.
* The :mod:`email` package is a library for managing email messages, including
MIME and other :rfc:`5322`-based message documents. Unlike :mod... | trusted_official_docs | CPython Docs | :mod:`xmlrpc.server` modules make implementing remote procedure calls into an almost trivial task. Despite the modules' names, no direct knowledge or handling of XML is needed.
* The :mod:`email` package is a library for managing email messages, including
MIME and other :rfc:`5322`-based message documents. Unlike :mod... | :mod:`xmlrpc.server` modules make implementing remote procedure calls into an almost trivial task. Despite the modules' names, no direct knowledge or handling of XML is needed.
* The :mod:`email` package is a library for managing email messages, including
MIME and other :rfc:`5322`-based message documents. Unlike :mod... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1e895034-3d5b-46c1-88cf-026ff331918f | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,226 | supabase-export-v2 | f57012f7b19edd6e | 81, 41, 50, 18, 33] >>> random.random() # random float from the interval [0.0, 1.0) 0.17970987693706186 >>> random.randrange(6) # random integer chosen from range(6) 4
The :mod:`statistics` module calculates basic statistical properties
(the mean, median, variance, etc.) of numeric data:: | trusted_official_docs | CPython Docs | 81, 41, 50, 18, 33] >>> random.random() # random float from the interval [0.0, 1.0) 0.17970987693706186 >>> random.randrange(6) # random integer chosen from range(6) 4
The :mod:`statistics` module calculates basic statistical properties
(the mean, median, variance, etc.) of numeric data:: | 81, 41, 50, 18, 33] >>> random.random() # random float from the interval [0.0, 1.0) 0.17970987693706186 >>> random.randrange(6) # random integer chosen from range(6) 4
The :mod:`statistics` module calculates basic statistical properties
(the mean, median, variance, etc.) of numeric data:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1f3c2bd6-2d3a-4e9c-b305-b349d979452e | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,219 | supabase-export-v2 | 00579bdf2f20154e | re >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') ['foot', 'fell', 'fastest'] >>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat') 'cat in the hat'
When only simple capabilities are needed, string methods are preferred because
they are easier to read and debug:: | trusted_official_docs | CPython Docs | re >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') ['foot', 'fell', 'fastest'] >>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat') 'cat in the hat'
When only simple capabilities are needed, string methods are preferred because
they are easier to read and debug:: | re >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') ['foot', 'fell', 'fastest'] >>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat') 'cat in the hat'
When only simple capabilities are needed, string methods are preferred because
they are easier to read and debug:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
21b12f6d-8428-4015-b17b-dd758e90daa5 | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,265 | supabase-export-v2 | af45c89c33a0a331 | Python has a "batteries included" philosophy. This is best seen through the sophisticated and robust capabilities of its larger packages. For example:
* The :mod:`xmlrpc.client` and :mod:`xmlrpc.server` modules make implementing
remote procedure calls into an almost trivial task. Despite the modules'
names, no direct... | trusted_official_docs | CPython Docs | Python has a "batteries included" philosophy. This is best seen through the sophisticated and robust capabilities of its larger packages. For example:
* The :mod:`xmlrpc.client` and :mod:`xmlrpc.server` modules make implementing
remote procedure calls into an almost trivial task. Despite the modules'
names, no direct... | Python has a "batteries included" philosophy. This is best seen through the sophisticated and robust capabilities of its larger packages. For example:
* The :mod:`xmlrpc.client` and :mod:`xmlrpc.server` modules make implementing
remote procedure calls into an almost trivial task. Despite the modules'
names, no direct... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2553839e-f354-45b1-8860-0d0e60b916c9 | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,237 | supabase-export-v2 | 8ab4766b843c7ffb | Dates and times ===============
The :mod:`datetime` module supplies classes for manipulating dates and times in
both simple and complex ways. While date and time arithmetic is supported, the
focus of the implementation is on efficient member extraction for output
formatting and manipulation. The module also supports ob... | trusted_official_docs | CPython Docs | Dates and times ===============
The :mod:`datetime` module supplies classes for manipulating dates and times in
both simple and complex ways. While date and time arithmetic is supported, the
focus of the implementation is on efficient member extraction for output
formatting and manipulation. The module also supports ob... | Dates and times ===============
The :mod:`datetime` module supplies classes for manipulating dates and times in
both simple and complex ways. While date and time arithmetic is supported, the
focus of the implementation is on efficient member extraction for output
formatting and manipulation. The module also supports ob... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2a935221-0315-4744-8cf5-134aa20b14ae | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,269 | supabase-export-v2 | ce30faad85080c0d | :mod:`sqlite3` module is a wrapper for the SQLite database library, providing a persistent database that can be updated and accessed using slightly nonstandard SQL syntax.
* Internationalization is supported by a number of modules including
:mod:`gettext`, :mod:`locale`, and the :mod:`codecs` package. | trusted_official_docs | CPython Docs | :mod:`sqlite3` module is a wrapper for the SQLite database library, providing a persistent database that can be updated and accessed using slightly nonstandard SQL syntax.
* Internationalization is supported by a number of modules including
:mod:`gettext`, :mod:`locale`, and the :mod:`codecs` package. | :mod:`sqlite3` module is a wrapper for the SQLite database library, providing a persistent database that can be updated and accessed using slightly nonstandard SQL syntax.
* Internationalization is supported by a number of modules including
:mod:`gettext`, :mod:`locale`, and the :mod:`codecs` package. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2b3da1dd-3fb5-4e1c-808f-7a78206cda1e | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,190 | supabase-export-v2 | 271d5496f149d370 | the current working directory 'C:\\Python315' >>> os.chdir('/server/accesslogs') # Change current working directory >>> os.system('mkdir today') # Run the command mkdir in the system shell 0
Be sure to use the ``import os`` style instead of ``from os import *``. This
will keep :func:`os.open` from shadowing the built-i... | trusted_official_docs | CPython Docs | the current working directory 'C:\\Python315' >>> os.chdir('/server/accesslogs') # Change current working directory >>> os.system('mkdir today') # Run the command mkdir in the system shell 0
Be sure to use the ``import os`` style instead of ``from os import *``. This
will keep :func:`os.open` from shadowing the built-i... | the current working directory 'C:\\Python315' >>> os.chdir('/server/accesslogs') # Change current working directory >>> os.system('mkdir today') # Run the command mkdir in the system shell 0
Be sure to use the ``import os`` style instead of ``from os import *``. This
will keep :func:`os.open` from shadowing the built-i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
306bfd59-1538-4317-915a-a0e0d14cf341 | CPython Docs | file://datasets/cpython/Doc/tutorial/stdlib.rst | unknown | fb1104f9-e853-4f6a-8c9f-85244484e234 | 53,228 | supabase-export-v2 | b8cf7e045e09b15a | >>> import statistics >>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5] >>> statistics.mean(data) 1.6071428571428572 >>> statistics.median(data) 1.25 >>> statistics.variance(data) 1.3720238095238095
The SciPy project <https://scipy.org> has many other modules for numerical
computations. | trusted_official_docs | CPython Docs | >>> import statistics >>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5] >>> statistics.mean(data) 1.6071428571428572 >>> statistics.median(data) 1.25 >>> statistics.variance(data) 1.3720238095238095
The SciPy project <https://scipy.org> has many other modules for numerical
computations. | >>> import statistics >>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5] >>> statistics.mean(data) 1.6071428571428572 >>> statistics.median(data) 1.25 >>> statistics.variance(data) 1.3720238095238095
The SciPy project <https://scipy.org> has many other modules for numerical
computations. | 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.