{"id":6609,"date":"2020-07-24T09:21:31","date_gmt":"2020-07-24T07:21:31","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=6609"},"modified":"2020-07-24T09:21:31","modified_gmt":"2020-07-24T07:21:31","slug":"what-is-a-sequence","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/what-is-a-sequence\/","title":{"rendered":"What is a sequence"},"content":{"rendered":"<h2>sequence<\/h2>\n<p>An\u00a0<a class=\"reference internal\" href=\"https:\/\/docs.python.org\/3\/glossary.html#term-iterable\"><span class=\"xref std std-term\">iterable<\/span><\/a>\u00a0which supports efficient element access using integer indices via the\u00a0<a class=\"reference internal\" title=\"object.__getitem__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__getitem__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__getitem__()<\/span><\/code><\/a>\u00a0special method and defines a\u00a0<a class=\"reference internal\" title=\"object.__len__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__len__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__len__()<\/span><\/code><\/a>\u00a0method that returns the length of the sequence. Some built-in sequence types are\u00a0<a class=\"reference internal\" title=\"list\" href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#list\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">list<\/span><\/code><\/a>,\u00a0<a class=\"reference internal\" title=\"str\" href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#str\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">str<\/span><\/code><\/a>,\u00a0<a class=\"reference internal\" title=\"tuple\" href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#tuple\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">tuple<\/span><\/code><\/a>, and\u00a0<a class=\"reference internal\" title=\"bytes\" href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#bytes\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">bytes<\/span><\/code><\/a>. Note that\u00a0<a class=\"reference internal\" title=\"dict\" href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#dict\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">dict<\/span><\/code><\/a>\u00a0also supports\u00a0<a class=\"reference internal\" title=\"object.__getitem__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__getitem__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__getitem__()<\/span><\/code><\/a>\u00a0and\u00a0<a class=\"reference internal\" title=\"object.__len__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__len__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__len__()<\/span><\/code><\/a>, but is considered a mapping rather than a sequence because the lookups use arbitrary\u00a0<a class=\"reference internal\" href=\"https:\/\/docs.python.org\/3\/glossary.html#term-immutable\"><span class=\"xref std std-term\">immutable<\/span><\/a>\u00a0keys rather than integers.<\/p>\n<p>The\u00a0<a class=\"reference internal\" title=\"collections.abc.Sequence\" href=\"https:\/\/docs.python.org\/3\/library\/collections.abc.html#collections.abc.Sequence\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">collections.abc.Sequence<\/span><\/code><\/a>\u00a0abstract base class defines a much richer interface that goes beyond just\u00a0<a class=\"reference internal\" title=\"object.__getitem__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__getitem__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__getitem__()<\/span><\/code><\/a>\u00a0and\u00a0<a class=\"reference internal\" title=\"object.__len__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__len__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__len__()<\/span><\/code><\/a>, adding\u00a0<code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">count()<\/span><\/code>,\u00a0<code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">index()<\/span><\/code>,\u00a0<a class=\"reference internal\" title=\"object.__contains__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__contains__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__contains__()<\/span><\/code><\/a>, and\u00a0<a class=\"reference internal\" title=\"object.__reversed__\" href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__reversed__\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">__reversed__()<\/span><\/code><\/a>. Types that implement this expanded interface can be registered explicitly using\u00a0<code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">register()<\/span><\/code>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"sequences\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/what-is-a-sequence\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[210],"tags":[848],"class_list":["post-6609","post","type-post","status-publish","format-standard","hentry","category-basics","tag-sequence"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":true,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/6609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=6609"}],"version-history":[{"count":1,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/6609\/revisions"}],"predecessor-version":[{"id":6610,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/6609\/revisions\/6610"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=6609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=6609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=6609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}