gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

456 行
33KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="Slice Objects" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/c-api/slice.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Ellipsis Object:" />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Ellipsis Object:" />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>Slice Objects &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="MemoryView objects" href="memoryview.html" />
  33. <link rel="prev" title="Descriptor Objects" href="descriptor.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/c-api/slice.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#">Slice Objects</a><ul>
  86. <li><a class="reference internal" href="#ellipsis-object">Ellipsis Object</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div>
  92. <h4>Previous topic</h4>
  93. <p class="topless"><a href="descriptor.html"
  94. title="previous chapter">Descriptor Objects</a></p>
  95. </div>
  96. <div>
  97. <h4>Next topic</h4>
  98. <p class="topless"><a href="memoryview.html"
  99. title="next chapter">MemoryView objects</a></p>
  100. </div>
  101. <div role="note" aria-label="source link">
  102. <h3>This Page</h3>
  103. <ul class="this-page-menu">
  104. <li><a href="../bugs.html">Report a Bug</a></li>
  105. <li>
  106. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/slice.rst"
  107. rel="nofollow">Show Source
  108. </a>
  109. </li>
  110. </ul>
  111. </div>
  112. </nav>
  113. </div>
  114. </div>
  115. <div class="related" role="navigation" aria-label="related navigation">
  116. <h3>Navigation</h3>
  117. <ul>
  118. <li class="right" style="margin-right: 10px">
  119. <a href="../genindex.html" title="General Index"
  120. accesskey="I">index</a></li>
  121. <li class="right" >
  122. <a href="../py-modindex.html" title="Python Module Index"
  123. >modules</a> |</li>
  124. <li class="right" >
  125. <a href="memoryview.html" title="MemoryView objects"
  126. accesskey="N">next</a> |</li>
  127. <li class="right" >
  128. <a href="descriptor.html" title="Descriptor Objects"
  129. accesskey="P">previous</a> |</li>
  130. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  131. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  132. <li class="switchers">
  133. <div class="language_switcher_placeholder"></div>
  134. <div class="version_switcher_placeholder"></div>
  135. </li>
  136. <li>
  137. </li>
  138. <li id="cpython-language-and-version">
  139. <a href="../index.html">3.12.3 Documentation</a> &#187;
  140. </li>
  141. <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &#187;</li>
  142. <li class="nav-item nav-item-2"><a href="concrete.html" accesskey="U">Concrete Objects Layer</a> &#187;</li>
  143. <li class="nav-item nav-item-this"><a href="">Slice Objects</a></li>
  144. <li class="right">
  145. <div class="inline-search" role="search">
  146. <form class="inline-search" action="../search.html" method="get">
  147. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  148. <input type="submit" value="Go" />
  149. </form>
  150. </div>
  151. |
  152. </li>
  153. <li class="right">
  154. <label class="theme-selector-label">
  155. Theme
  156. <select class="theme-selector" oninput="activateTheme(this.value)">
  157. <option value="auto" selected>Auto</option>
  158. <option value="light">Light</option>
  159. <option value="dark">Dark</option>
  160. </select>
  161. </label> |</li>
  162. </ul>
  163. </div>
  164. <div class="document">
  165. <div class="documentwrapper">
  166. <div class="bodywrapper">
  167. <div class="body" role="main">
  168. <section id="slice-objects">
  169. <span id="id1"></span><h1>Slice Objects<a class="headerlink" href="#slice-objects" title="Link to this heading">¶</a></h1>
  170. <dl class="c var">
  171. <dt class="sig sig-object c" id="c.PySlice_Type">
  172. <a class="reference internal" href="type.html#c.PyTypeObject" title="PyTypeObject"><span class="n"><span class="pre">PyTypeObject</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PySlice_Type</span></span></span><a class="headerlink" href="#c.PySlice_Type" title="Link to this definition">¶</a><br /></dt>
  173. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>The type object for slice objects. This is the same as <a class="reference internal" href="../library/functions.html#slice" title="slice"><code class="xref py py-class docutils literal notranslate"><span class="pre">slice</span></code></a> in the
  174. Python layer.</p>
  175. </dd></dl>
  176. <dl class="c function">
  177. <dt class="sig sig-object c" id="c.PySlice_Check">
  178. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PySlice_Check</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">ob</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySlice_Check" title="Link to this definition">¶</a><br /></dt>
  179. <dd><p>Return true if <em>ob</em> is a slice object; <em>ob</em> must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. This
  180. function always succeeds.</p>
  181. </dd></dl>
  182. <dl class="c function">
  183. <dt class="sig sig-object c" id="c.PySlice_New">
  184. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">PySlice_New</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">stop</span></span>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">step</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySlice_New" title="Link to this definition">¶</a><br /></dt>
  185. <dd><em class="refcount">Return value: New reference.</em><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Return a new slice object with the given values. The <em>start</em>, <em>stop</em>, and
  186. <em>step</em> parameters are used as the values of the slice object attributes of
  187. the same names. Any of the values may be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, in which case the
  188. <code class="docutils literal notranslate"><span class="pre">None</span></code> will be used for the corresponding attribute. Return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if
  189. the new object could not be allocated.</p>
  190. </dd></dl>
  191. <dl class="c function">
  192. <dt class="sig sig-object c" id="c.PySlice_GetIndices">
  193. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PySlice_GetIndices</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">slice</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">length</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">stop</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">step</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySlice_GetIndices" title="Link to this definition">¶</a><br /></dt>
  194. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Retrieve the start, stop and step indices from the slice object <em>slice</em>,
  195. assuming a sequence of length <em>length</em>. Treats indices greater than
  196. <em>length</em> as errors.</p>
  197. <p>Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> on success and <code class="docutils literal notranslate"><span class="pre">-1</span></code> on error with no exception set (unless one of
  198. the indices was not <code class="docutils literal notranslate"><span class="pre">None</span></code> and failed to be converted to an integer,
  199. in which case <code class="docutils literal notranslate"><span class="pre">-1</span></code> is returned with an exception set).</p>
  200. <p>You probably do not want to use this function.</p>
  201. <div class="versionchanged">
  202. <p><span class="versionmodified changed">Changed in version 3.2: </span>The parameter type for the <em>slice</em> parameter was <code class="docutils literal notranslate"><span class="pre">PySliceObject*</span></code>
  203. before.</p>
  204. </div>
  205. </dd></dl>
  206. <dl class="c function">
  207. <dt class="sig sig-object c" id="c.PySlice_GetIndicesEx">
  208. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PySlice_GetIndicesEx</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">slice</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">length</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">stop</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">step</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">slicelength</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySlice_GetIndicesEx" title="Link to this definition">¶</a><br /></dt>
  209. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a>.</em><p>Usable replacement for <a class="reference internal" href="#c.PySlice_GetIndices" title="PySlice_GetIndices"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndices()</span></code></a>. Retrieve the start,
  210. stop, and step indices from the slice object <em>slice</em> assuming a sequence of
  211. length <em>length</em>, and store the length of the slice in <em>slicelength</em>. Out
  212. of bounds indices are clipped in a manner consistent with the handling of
  213. normal slices.</p>
  214. <p>Returns <code class="docutils literal notranslate"><span class="pre">0</span></code> on success and <code class="docutils literal notranslate"><span class="pre">-1</span></code> on error with exception set.</p>
  215. <div class="admonition note">
  216. <p class="admonition-title">Note</p>
  217. <p>This function is considered not safe for resizable sequences.
  218. Its invocation should be replaced by a combination of
  219. <a class="reference internal" href="#c.PySlice_Unpack" title="PySlice_Unpack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_Unpack()</span></code></a> and <a class="reference internal" href="#c.PySlice_AdjustIndices" title="PySlice_AdjustIndices"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_AdjustIndices()</span></code></a> where</p>
  220. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PySlice_GetIndicesEx</span><span class="p">(</span><span class="n">slice</span><span class="p">,</span><span class="w"> </span><span class="n">length</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">start</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">stop</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">step</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">slicelength</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  221. <span class="w"> </span><span class="c1">// return error</span>
  222. <span class="p">}</span>
  223. </pre></div>
  224. </div>
  225. <p>is replaced by</p>
  226. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PySlice_Unpack</span><span class="p">(</span><span class="n">slice</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">start</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">stop</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">step</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  227. <span class="w"> </span><span class="c1">// return error</span>
  228. <span class="p">}</span>
  229. <span class="n">slicelength</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PySlice_AdjustIndices</span><span class="p">(</span><span class="n">length</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">start</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">stop</span><span class="p">,</span><span class="w"> </span><span class="n">step</span><span class="p">);</span>
  230. </pre></div>
  231. </div>
  232. </div>
  233. <div class="versionchanged">
  234. <p><span class="versionmodified changed">Changed in version 3.2: </span>The parameter type for the <em>slice</em> parameter was <code class="docutils literal notranslate"><span class="pre">PySliceObject*</span></code>
  235. before.</p>
  236. </div>
  237. <div class="versionchanged">
  238. <p><span class="versionmodified changed">Changed in version 3.6.1: </span>If <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> is not set or set to the value between <code class="docutils literal notranslate"><span class="pre">0x03050400</span></code>
  239. and <code class="docutils literal notranslate"><span class="pre">0x03060000</span></code> (not including) or <code class="docutils literal notranslate"><span class="pre">0x03060100</span></code> or higher
  240. <code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndicesEx()</span></code> is implemented as a macro using
  241. <code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_Unpack()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_AdjustIndices()</span></code>.
  242. Arguments <em>start</em>, <em>stop</em> and <em>step</em> are evaluated more than once.</p>
  243. </div>
  244. <div class="deprecated">
  245. <p><span class="versionmodified deprecated">Deprecated since version 3.6.1: </span>If <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> is set to the value less than <code class="docutils literal notranslate"><span class="pre">0x03050400</span></code> or
  246. between <code class="docutils literal notranslate"><span class="pre">0x03060000</span></code> and <code class="docutils literal notranslate"><span class="pre">0x03060100</span></code> (not including)
  247. <code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndicesEx()</span></code> is a deprecated function.</p>
  248. </div>
  249. </dd></dl>
  250. <dl class="c function">
  251. <dt class="sig sig-object c" id="c.PySlice_Unpack">
  252. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PySlice_Unpack</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">slice</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">stop</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">step</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySlice_Unpack" title="Link to this definition">¶</a><br /></dt>
  253. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.7.</em><p>Extract the start, stop and step data members from a slice object as
  254. C integers. Silently reduce values larger than <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_MAX</span></code> to
  255. <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_MAX</span></code>, silently boost the start and stop values less than
  256. <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_MIN</span></code> to <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_MIN</span></code>, and silently boost the step
  257. values less than <code class="docutils literal notranslate"><span class="pre">-PY_SSIZE_T_MAX</span></code> to <code class="docutils literal notranslate"><span class="pre">-PY_SSIZE_T_MAX</span></code>.</p>
  258. <p>Return <code class="docutils literal notranslate"><span class="pre">-1</span></code> on error, <code class="docutils literal notranslate"><span class="pre">0</span></code> on success.</p>
  259. <div class="versionadded">
  260. <p><span class="versionmodified added">New in version 3.6.1.</span></p>
  261. </div>
  262. </dd></dl>
  263. <dl class="c function">
  264. <dt class="sig sig-object c" id="c.PySlice_AdjustIndices">
  265. <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PySlice_AdjustIndices</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">length</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">start</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">stop</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">step</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySlice_AdjustIndices" title="Link to this definition">¶</a><br /></dt>
  266. <dd><em class="stableabi"> Part of the <a class="reference internal" href="stable.html#stable"><span class="std std-ref">Stable ABI</span></a> since version 3.7.</em><p>Adjust start/end slice indices assuming a sequence of the specified length.
  267. Out of bounds indices are clipped in a manner consistent with the handling
  268. of normal slices.</p>
  269. <p>Return the length of the slice. Always successful. Doesn’t call Python
  270. code.</p>
  271. <div class="versionadded">
  272. <p><span class="versionmodified added">New in version 3.6.1.</span></p>
  273. </div>
  274. </dd></dl>
  275. <section id="ellipsis-object">
  276. <h2>Ellipsis Object<a class="headerlink" href="#ellipsis-object" title="Link to this heading">¶</a></h2>
  277. <dl class="c var">
  278. <dt class="sig sig-object c" id="c.Py_Ellipsis">
  279. <a class="reference internal" href="structures.html#c.PyObject" title="PyObject"><span class="n"><span class="pre">PyObject</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">Py_Ellipsis</span></span></span><a class="headerlink" href="#c.Py_Ellipsis" title="Link to this definition">¶</a><br /></dt>
  280. <dd><p>The Python <code class="docutils literal notranslate"><span class="pre">Ellipsis</span></code> object. This object has no methods. Like
  281. <a class="reference internal" href="none.html#c.Py_None" title="Py_None"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_None</span></code></a>, it is an <a class="reference external" href="https://peps.python.org/pep-0683/">immortal</a>.
  282. singleton object.</p>
  283. <div class="versionchanged">
  284. <p><span class="versionmodified changed">Changed in version 3.12: </span><a class="reference internal" href="#c.Py_Ellipsis" title="Py_Ellipsis"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_Ellipsis</span></code></a> is immortal.</p>
  285. </div>
  286. </dd></dl>
  287. </section>
  288. </section>
  289. <div class="clearer"></div>
  290. </div>
  291. </div>
  292. </div>
  293. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  294. <div class="sphinxsidebarwrapper">
  295. <div>
  296. <h3><a href="../contents.html">Table of Contents</a></h3>
  297. <ul>
  298. <li><a class="reference internal" href="#">Slice Objects</a><ul>
  299. <li><a class="reference internal" href="#ellipsis-object">Ellipsis Object</a></li>
  300. </ul>
  301. </li>
  302. </ul>
  303. </div>
  304. <div>
  305. <h4>Previous topic</h4>
  306. <p class="topless"><a href="descriptor.html"
  307. title="previous chapter">Descriptor Objects</a></p>
  308. </div>
  309. <div>
  310. <h4>Next topic</h4>
  311. <p class="topless"><a href="memoryview.html"
  312. title="next chapter">MemoryView objects</a></p>
  313. </div>
  314. <div role="note" aria-label="source link">
  315. <h3>This Page</h3>
  316. <ul class="this-page-menu">
  317. <li><a href="../bugs.html">Report a Bug</a></li>
  318. <li>
  319. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/slice.rst"
  320. rel="nofollow">Show Source
  321. </a>
  322. </li>
  323. </ul>
  324. </div>
  325. </div>
  326. <div id="sidebarbutton" title="Collapse sidebar">
  327. <span>«</span>
  328. </div>
  329. </div>
  330. <div class="clearer"></div>
  331. </div>
  332. <div class="related" role="navigation" aria-label="related navigation">
  333. <h3>Navigation</h3>
  334. <ul>
  335. <li class="right" style="margin-right: 10px">
  336. <a href="../genindex.html" title="General Index"
  337. >index</a></li>
  338. <li class="right" >
  339. <a href="../py-modindex.html" title="Python Module Index"
  340. >modules</a> |</li>
  341. <li class="right" >
  342. <a href="memoryview.html" title="MemoryView objects"
  343. >next</a> |</li>
  344. <li class="right" >
  345. <a href="descriptor.html" title="Descriptor Objects"
  346. >previous</a> |</li>
  347. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  348. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  349. <li class="switchers">
  350. <div class="language_switcher_placeholder"></div>
  351. <div class="version_switcher_placeholder"></div>
  352. </li>
  353. <li>
  354. </li>
  355. <li id="cpython-language-and-version">
  356. <a href="../index.html">3.12.3 Documentation</a> &#187;
  357. </li>
  358. <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &#187;</li>
  359. <li class="nav-item nav-item-2"><a href="concrete.html" >Concrete Objects Layer</a> &#187;</li>
  360. <li class="nav-item nav-item-this"><a href="">Slice Objects</a></li>
  361. <li class="right">
  362. <div class="inline-search" role="search">
  363. <form class="inline-search" action="../search.html" method="get">
  364. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  365. <input type="submit" value="Go" />
  366. </form>
  367. </div>
  368. |
  369. </li>
  370. <li class="right">
  371. <label class="theme-selector-label">
  372. Theme
  373. <select class="theme-selector" oninput="activateTheme(this.value)">
  374. <option value="auto" selected>Auto</option>
  375. <option value="light">Light</option>
  376. <option value="dark">Dark</option>
  377. </select>
  378. </label> |</li>
  379. </ul>
  380. </div>
  381. <div class="footer">
  382. &copy;
  383. <a href="../copyright.html">
  384. Copyright
  385. </a>
  386. 2001-2024, Python Software Foundation.
  387. <br />
  388. This page is licensed under the Python Software Foundation License Version 2.
  389. <br />
  390. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  391. <br />
  392. See <a href="/license.html">History and License</a> for more information.<br />
  393. <br />
  394. The Python Software Foundation is a non-profit corporation.
  395. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  396. <br />
  397. <br />
  398. Last updated on Apr 09, 2024 (13:47 UTC).
  399. <a href="/bugs.html">Found a bug</a>?
  400. <br />
  401. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  402. </div>
  403. </body>
  404. </html>
上海开阖软件有限公司 沪ICP备12045867号-1