

{"id":9376,"date":"2018-02-27T10:32:15","date_gmt":"2018-02-27T05:02:15","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=9376"},"modified":"2026-04-21T14:59:17","modified_gmt":"2026-04-21T09:29:17","slug":"python-sequence","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-sequence\/","title":{"rendered":"Python Sequence and Collections &#8211; Operations, Functions, Methods"},"content":{"rendered":"<p>This blog is dedicated to a revision of the\u00a0Python sequence and collections.<\/p>\n<p>In this Python Sequence Tutorial, we will discuss 6 types of Sequence: String, list, tuples, Byte sequences, byte array, and range object.<\/p>\n<p>Moreover, we will discuss Python sequence operations, functions, and methods. At last, we will cover python collection: sets and dictionaries.<\/p>\n<p>So, let&#8217;s start Python Sequence and Collections<\/p>\n<h3>What is a Python Sequence?<\/h3>\n<p>So, what is a Python sequence, and how does it differ from a Python collection?<\/p>\n<p>A sequence is a group of items with a deterministic ordering. The order in which we put them in is the order in which we get an item out of them.<\/p>\n<p>Python offers six types of sequences. Let\u2019s discuss them.<\/p>\n<h4>1. Python Strings<\/h4>\n<p>A string is a group of characters. Since Python has no provision for arrays, we simply use strings. This is how we declare a string in Python:<\/p>\n<p>Python Sequence or Collection<\/p>\n<p>We can use a pair of single or double quotes. And like we\u2019ve always said, Python is dynamically-typed. Every string object is of the type \u2018str\u2019.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; type(name)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&lt;class &#8216;str&#8217;&gt;<\/p>\n<\/div>\n<p>To declare an empty string, we may use the function str():<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; name=str()\r\n&gt;&gt;&gt; name\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8221;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; name=str('Ayushi')\r\n&gt;&gt;&gt; name\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;Ayushi&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; name[3]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;s&#8217;<\/p>\n<\/div>\n<h4>2. Python Lists<\/h4>\n<p>Since Python does not have arrays, it has lists. A list is an ordered group of items. To declare it, we use square brackets.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; groceries=['milk','bread','eggs']\r\n&gt;&gt;&gt; groceries[1]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;bread&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; groceries[:2]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>[&#8216;milk&#8217;, &#8216;bread&#8217;]<\/p>\n<\/div>\n<p>A list in Python can hold all kinds of items; this is what makes it heterogeneous.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; mylist=[1,'2',3.0,False]<\/pre>\n<p>Also, a list is mutable. This means we can change a value.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; groceries[0]='cheese'\r\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>[&#8216;cheese&#8217;, &#8216;bread&#8217;, &#8216;eggs&#8217;]<\/p>\n<\/div>\n<p>A list may also contain functions.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; groceries[0]='cheese'\r\n&gt;&gt;&gt; groceries<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>print(&#8220;Hi&#8221;)<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt;\u00a0newlist=[sayhi,sayhi]\r\n&gt;&gt;&gt;\u00a0newlist[0]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&lt;function sayhi at 0x05907300&gt;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; newlist[0]()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Hi<\/p>\n<\/div>\n<h4>3. Python Tuples<\/h4>\n<p>A tuple in Python, in effect, is an immutable group of items. When we say immutable, we mean we cannot change a single value once we declare it.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; name=('Ayushi','Sharma')\r\n&gt;&gt;&gt; type(name)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&lt;class &#8216;tuple&#8217;&gt;<\/p>\n<\/div>\n<p>We can also use the function tuple().<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; name=tuple(['Ayushi','Sharma'])\r\n&gt;&gt;&gt; name<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>(&#8216;Ayushi&#8217;, &#8216;Sharma&#8217;)<\/p>\n<\/div>\n<p>Like we said, a tuple is immutable. Let\u2019s try changing a value.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; name[0]='Avery'<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#594&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>name[0]=&#8217;Avery&#8217;<\/p>\n<p>TypeError: &#8216;tuple&#8217; object does not support item assignment<\/p>\n<\/div>\n<h4>4. Byte Sequences in Python<\/h4>\n<p>The function bytes() returns an immutable bytes object. We dealt with this when we talked about Built-in Functions in Python.<\/p>\n<p>Let\u2019s take a few examples.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; bytes(5)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>b&#8217;\\x00\\x00\\x00\\x00\\x00&#8242;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; bytes([1,2,3,4,5])<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>b&#8217;\\x01\\x02\\x03\\x04\\x05&#8242;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; bytes('hello','utf-8')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>b &#8216;hello&#8217;<\/p>\n<\/div>\n<p>Here, utf-8 is the encoding we used.<\/p>\n<p>Since it is immutable, if we try to change an item, it will raise a TypeError.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=bytes([1,2,3,4,5])\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>b&#8217;\\x01\\x02\\x03\\x04\\x05&#8242;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a[4]=3\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#46&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>a[4]=3<\/p>\n<p>TypeError: &#8216;bytes&#8217; object does not support item assignment<\/p>\n<\/div>\n<h4>5. Byte Arrays in Python<\/h4>\n<p>In that article, we discussed this one too. A bytesarray object is like a bytes object, but it is mutable.<\/p>\n<p>It returns an array of the given byte size.<\/p>\n<ul>\n<li>It can be created only by using the bytearray() constructor.<\/li>\n<li>The list method is being used on a byte array.<\/li>\n<li>It is used to manage frequent changes or buffers.<\/li>\n<li>It is commonly used in low-level programming.<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=bytearray(4)\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>bytearray(b&#8217;\\x00\\x00\\x00\\x00&#8242;)<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=bytearray(4)\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>bytearray(b&#8217;\\x00\\x00\\x00\\x00\\x01&#8242;)<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a[0]=1\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>bytearray(b&#8217;\\x01\\x00\\x00\\x00\\x01&#8242;)<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a[0]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>1<\/p>\n<\/div>\n<p>Let\u2019s try doing this on a list.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; bytearray([1,2,3,4])<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>bytearray(b&#8217;\\x01\\x02\\x03\\x04&#8242;)<\/p>\n<\/div>\n<p>Finally, let\u2019s try changing a value.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=bytearray([1,2,3,4,5])\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>bytearray(b&#8217;\\x01\\x02\\x03\\x04\\x05&#8242;)<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a[4]=3\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>bytearray(b&#8217;\\x01\\x02\\x03\\x04\\x03&#8242;)<\/p>\n<\/div>\n<p>See? It is mutable.<\/p>\n<h4>6. range() objects in Python<\/h4>\n<p>A range() object lends us a range to iterate on; it gives us a list of numbers.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=range(4)\r\n&gt;&gt;&gt; type(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&lt;class &#8216;range&#8217;&gt;<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; for i in range(7,0,-1):\r\n     print(i)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<br \/>\n6<br \/>\n5<br \/>\n4<br \/>\n3<br \/>\n2<br \/>\n1<\/div>\n<p>We took an entire post on Range in Python.<\/p>\n<h3>Python Sequence Operations<\/h3>\n<p>Since we classify into sequences and collections, we might as well discuss the operations we can perform on them. For simplicity, we will demonstrate these on strings.<\/p>\n<p><b>1. Concatenation Operation<\/b><\/p>\n<p>Concatenation adds the second operand after the first one.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; 'Ayu'+'shi'<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Ayushi&#8217;<\/div>\n<div><\/div>\n<div class=\"code-output\"><b>2. Integer Multiplication Operation<\/b><\/div>\n<p>We can make a string print twice by multiplying it by 2.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; 'ba'+'na'*2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;banana&#8217;<\/div>\n<div><\/div>\n<div class=\"code-output\"><strong>3.<\/strong> <b>Membership Operation<\/b><\/div>\n<p>To check if a value is a member of a sequence, we use the \u2018in\u2019 operator.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; 'men' in 'Disappointment'<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<div><\/div>\n<div class=\"code-output\"><b>4. Python Slice<\/b><\/div>\n<p>Sometimes, we only want a part of a sequence, and not all of it. We do it with the slicing operator.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; 'Ayushi'[1:4]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;yus&#8217;<\/div>\n<h3>Python Sequence Functions<\/h3>\n<h4><b style=\"font-size: 16px\">1. len() function in Python sequence<\/b><\/h4>\n<p>A very common and useful function to pass a sequence to is len(). It returns the length of the Python sequence.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; len('Ayushi')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">6<\/div>\n<h4 class=\"code-output\"><b>2. min() and max() function in Python sequence<\/b><\/h4>\n<p>min() and max() return the lowest and highest values, respectively, in a Python sequence.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; min('cat')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;a&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; max('cat')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;t&#8217;<\/div>\n<p>This comparison is based on ASCII values.<\/p>\n<h3>Python Sequence Methods<\/h3>\n<p>There are some methods that we can call on a Python sequence:<\/p>\n<h4><b>1. Python index() method<\/b><\/h4>\n<p>This method returns the index of the first occurrence of a value.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; 'banana'.index('n')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<h4 class=\"code-output\"><b>2. Python count() method<\/b><\/h4>\n<p>count() returns the number of occurrences of a value in a Python sequence.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; 'banana'.count('na')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; 'banana'.count('a')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">3<\/div>\n<h3>Python Collections<\/h3>\n<p>Python collections, unlike sequences, do not have a deterministic ordering. Examples include sets and dictionaries.<\/p>\n<p>In a collection, while ordering is arbitrary, physically, they do have an order.<\/p>\n<p>Every time we visit a set, we get its items in the same order. However, if we add or remove an item, it may affect the order.<\/p>\n<h4>1. Python Set<\/h4>\n<p>A set, in Python, is like a mathematical set in Python. It does not hold duplicates. We can declare a set in two ways:<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; nums={2,1,3,2}\r\n&gt;&gt;&gt; nums<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">{1, 2, 3}<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; nums=set([1,3,2])\r\n&gt;&gt;&gt; nums<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">{1, 2, 3}<\/div>\n<p>A set is mutable.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; nums.discard(2)\r\n&gt;&gt;&gt; nums<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">{1, 3}<\/div>\n<p>But it may not contain mutable items like lists, dictionaries, or other sets.<\/p>\n<h4>2. Python Dictionaries<\/h4>\n<p>Think of a dictionary as a real-life dictionary. It holds key-value pairs, and this is how we declare it:<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a={'name':1,'dob':2}<\/pre>\n<p>Or, you could do:<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=dict()\r\n&gt;&gt;&gt; a['name']=1\r\n&gt;&gt;&gt; a['dob']=2\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">{&#8216;name&#8217;: 1, &#8216;dob&#8217;: 2}<\/div>\n<p>We have yet another way to create a dictionary- a dictionary comprehension.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a={i:2**i for i in range(4)}\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">{0: 1, 1: 2, 2: 4, 3: 8}<\/div>\n<p>However, a key cannot be of an unhashable type.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a={[1,2,3]:1,1:[1,2,3]}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#629&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>a={[1,2,3]:1,1:[1,2,3]}<\/p>\n<p>TypeError: unhashable type: &#8216;list&#8217;<\/p>\n<\/div>\n<p>So, this was all about the Python sequence and collections tutorial. Hope you like our explanation.<\/p>\n<h3>Python Interview Questions on Sequences and Collections<\/h3>\n<p>1. What are Python Collections and Sequences?<\/p>\n<p>2. What are the different types of Sequences in Python?<\/p>\n<p>3. Is string a collection in Python?<\/p>\n<p>4. What are collection data types in Python?<\/p>\n<p>5. Is set a sequence in Python?<\/p>\n<h3>Conclusion<\/h3>\n<p>In Python, the umbrella term sequence covers any ordered series that supports length, slicing, and iteration\u2014lists, tuples, strings, and ranges all qualify. A collection is broader, meaning any container that groups objects, ordered or not, such as sets and dictionaries.<\/p>\n<p>The common sequence protocol lets you write one function that prints the first three items of any sequence without checking its exact type. Collections.abc provides formal abstract base classes like Sequence, MutableSequence, and Mapping so you can test or build your own custom objects that act like the built-in ones.<\/p>\n<p>Grasping these roots helps you understand why strings behave like read-only lists of characters and why you can slice a range to get another range.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog is dedicated to a revision of the\u00a0Python sequence and collections. In this Python Sequence Tutorial, we will discuss 6 types of Sequence: String, list, tuples, Byte sequences, byte array, and range object.&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":36387,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[2256,4394,9893,10429,10496,10649,10830,10835,10900],"class_list":["post-9376","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-byte-sequence","tag-examples-of-python-collection-modules","tag-poython-collections","tag-python-collections","tag-python-dictionaries","tag-python-lists","tag-python-sequences","tag-python-setpython-collection-module","tag-python-tuple"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Sequence and Collections - Operations, Functions, Methods - DataFlair<\/title>\n<meta name=\"description\" content=\"Python Sequence and Collection: Learn Python Sequences, Lists, Python Tuples, Byte Sequences, Python Collections, Python Set, Python Dictionary\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-sequence\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Sequence and Collections - Operations, Functions, Methods - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python Sequence and Collection: Learn Python Sequences, Lists, Python Tuples, Byte Sequences, Python Collections, Python Set, Python Dictionary\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-sequence\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-27T05:02:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-21T09:29:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Sequences-or-Collections-in-Python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Sequence and Collections - Operations, Functions, Methods - DataFlair","description":"Python Sequence and Collection: Learn Python Sequences, Lists, Python Tuples, Byte Sequences, Python Collections, Python Set, Python Dictionary","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-sequence\/","og_locale":"en_US","og_type":"article","og_title":"Python Sequence and Collections - Operations, Functions, Methods - DataFlair","og_description":"Python Sequence and Collection: Learn Python Sequences, Lists, Python Tuples, Byte Sequences, Python Collections, Python Set, Python Dictionary","og_url":"https:\/\/data-flair.training\/blogs\/python-sequence\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-02-27T05:02:15+00:00","article_modified_time":"2026-04-21T09:29:17+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Sequences-or-Collections-in-Python.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Sequence and Collections &#8211; Operations, Functions, Methods","datePublished":"2018-02-27T05:02:15+00:00","dateModified":"2026-04-21T09:29:17+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/"},"wordCount":1211,"commentCount":6,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Sequences-or-Collections-in-Python.jpg","keywords":["byte sequence","examples of Python collection modules","poython collections","python collections","python dictionaries","python lists","Python Sequences","python setpython collection module","Python tuple"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-sequence\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/","url":"https:\/\/data-flair.training\/blogs\/python-sequence\/","name":"Python Sequence and Collections - Operations, Functions, Methods - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Sequences-or-Collections-in-Python.jpg","datePublished":"2018-02-27T05:02:15+00:00","dateModified":"2026-04-21T09:29:17+00:00","description":"Python Sequence and Collection: Learn Python Sequences, Lists, Python Tuples, Byte Sequences, Python Collections, Python Set, Python Dictionary","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-sequence\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Sequences-or-Collections-in-Python.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Sequences-or-Collections-in-Python.jpg","width":1200,"height":628,"caption":"Python Sequence and Collections - Operations, Functions, Methods"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-sequence\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Sequence and Collections &#8211; Operations, Functions, Methods"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/9376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=9376"}],"version-history":[{"count":15,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/9376\/revisions"}],"predecessor-version":[{"id":147748,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/9376\/revisions\/147748"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/36387"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=9376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=9376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=9376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}