

{"id":22134,"date":"2018-07-21T03:00:55","date_gmt":"2018-07-20T21:30:55","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=22134"},"modified":"2026-04-22T15:25:01","modified_gmt":"2026-04-22T09:55:01","slug":"python-array-module","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-array-module\/","title":{"rendered":"Python Array Module &#8211; How to Create and Import Array in Python"},"content":{"rendered":"<p>Today in this Python Array Tutorial, we will learn about arrays in Python Programming. Here, we will discuss how Python array import module and how can we create Array.<\/p>\n<p>Along with this, we will cover the Python Array Class Modules and Data Items.<\/p>\n<h3>What is a Python Array Module?<\/h3>\n<p><i>Python array<\/i> <em>module<\/em> gives us an object type that we can use to denote an array. This is a collection of a type of values.<\/p>\n<p>In a way, this is like a Python list, but we specify a type at the time of creation.<\/p>\n<p><strong>Python Array Module can be used in:<\/strong><\/p>\n<ul>\n<li>Numerical computing<\/li>\n<li>Large datasets<\/li>\n<li>Data science<\/li>\n<li>Artificial Intelligence<\/li>\n<\/ul>\n<p>Here\u2019s a list of such type codes-<\/p>\n<table width=\"638\" cellspacing=\"0\" cellpadding=\"7\">\n<colgroup>\n<col width=\"106\" \/>\n<col width=\"142\" \/>\n<col width=\"188\" \/>\n<col width=\"145\" \/> <\/colgroup>\n<tbody>\n<tr>\n<td width=\"106\">\n<p align=\"center\"><b>Type Code<\/b><\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\"><b>C Type<\/b><\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\"><b>Python Type<\/b><\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\"><b>Minimum size (bytes)<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">b<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">signed char<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">B<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">unsigned char<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">u<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">Py_UNICODE<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">Unicode character;<\/p>\n<p align=\"center\">deprecated since Python 3.3<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">h<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">signed short<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">H<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">unsigned short<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">i<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">signed int<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">I<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">unsigned int<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">l<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">signed long<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">L<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">unsigned long<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">q<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">signed long long<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">8<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">Q<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">unsigned long long<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">int<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">8<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">f<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">float<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">float<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">4<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"106\">\n<p align=\"center\">d<\/p>\n<\/td>\n<td width=\"142\">\n<p align=\"center\">double<\/p>\n<\/td>\n<td width=\"188\">\n<p align=\"center\">float<\/p>\n<\/td>\n<td width=\"145\">\n<p align=\"center\">8<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>How to Import Python Array Module?<\/h3>\n<p>If a Python array is installed on your machine, you can import it as:<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import array<\/pre>\n<h3>How to Create a Python Array?<\/h3>\n<p>You can create an array using the following piece of code-<\/p>\n<pre class=\"EnlighterJSRAW\">class array.array(typecode[,initializer])<\/pre>\n<p>This creates a new array with items of the type specified by the type code. You can optionally provide an initializer value- a list.<\/p>\n<p>Let\u2019s try creating an array in Python.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr=array.array('i',[1,3,4])\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [1, 3, 4])<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; array.array('u', 'hello \\u2641')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;u&#8217;, &#8216;hello <span style=\"font-family: 'MS Gothic', serif\">\u2641<\/span>&#8216;)<\/div>\n<h3 class=\"western\">Python Array Class &#8211; Data Items<\/h3>\n<p>The class <i>array<\/i> has the following data items-<\/p>\n<div id=\"attachment_22150\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-array-class-Data-Items.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22150\" class=\"wp-image-22150 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-array-class-Data-Items.jpg\" alt=\"Python Array Class - Data Items\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-array-class-Data-Items.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-array-class-Data-Items-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-array-class-Data-Items-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-array-class-Data-Items-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-array-class-Data-Items-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-22150\" class=\"wp-caption-text\">Python Arrays Class &#8211; Data Items<\/p><\/div>\n<h4 class=\"western\">1. array.typecodes in Python<\/h4>\n<p>This is a string with all available type codes- the ones in the table above.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; array.typecodes<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;bBuhHiIlLqQfd&#8217;<\/div>\n<h4 class=\"western\">2. array.typecode in Python<\/h4>\n<p>This gives us the type code character we used when creating the array in Python.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.typecode<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;i&#8217;<\/div>\n<h4>3. array.itemsize in Python<\/h4>\n<p>This returns the number of bytes one item from the Python array takes internally.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.itemsize<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">4<\/div>\n<h3 class=\"western\">Python Array Class &#8211; Methods<\/h3>\n<p>Now, which methods does Array Class support? Here you go:<\/p>\n<div id=\"attachment_22165\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Class-Methods-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22165\" class=\"wp-image-22165 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Class-Methods-01.jpg\" alt=\"Python Array Class - Methods\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Class-Methods-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Class-Methods-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Class-Methods-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Class-Methods-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Class-Methods-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-22165\" class=\"wp-caption-text\">Python Array Class &#8211; Methods<\/p><\/div>\n<h4 class=\"western\">1. array.append(x) in Python<\/h4>\n<p>This appends the item <i>x<\/i> to the array.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.append(2)\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [1, 3, 4, 2])<\/div>\n<h4 class=\"western\">2. array.buffer_info() in Python<\/h4>\n<p>This returns a tuple that holds the address in memory and the length of elements in the buffer that holds the contents of the array.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.buffer_info()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(43560864, 4)<\/div>\n<h4 class=\"western\">3. array.byteswap() in Python<\/h4>\n<p>This performs an operation of bytes wap on an array.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.byteswap()\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [16777216, 50331648, 67108864, 33554432])<\/div>\n<h4 class=\"western\">4. array.count(x) in Python<\/h4>\n<p>Let\u2019s find out how many 3s there are in our Python array.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr=array.array('i',[1,3,2,4,3,5])\r\n&gt;&gt;&gt; arr.count(3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<h4 class=\"western\">5. array.extend(iterable) in Python<\/h4>\n<p>This attaches the iterable to the end of the array in Python.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.extend([7,9,8])\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [1, 3, 2, 4, 3, 5, 7, 9, 8])<\/div>\n<p>But if you add another array, make sure it is the same type. The following code throws an error.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.extend(array.array('u',['H','e','l','l','o']))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Traceback (most recent call last):<br \/>\nFile &#8220;&lt;pyshell#19&gt;&#8221;, line 1, in &lt;module&gt;<br \/>\narr.extend(array.array(&#8216;u&#8217;,[&#8216;H&#8217;,&#8217;e&#8217;,&#8217;l&#8217;,&#8217;l&#8217;,&#8217;o&#8217;]))<br \/>\nTypeError: can only extend with array of same kind<\/div>\n<h4 class=\"western\">6. array.fromlist(list) in Python<\/h4>\n<p>This appends item from a list to the Python arrays.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.fromlist([9,0])\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [1, 3, 2, 4, 3, 5, 7, 9, 8, 9, 0])<\/div>\n<h4 class=\"western\">7. array.fromunicode(s) in Python<\/h4>\n<p>This appends the Unicode string to the one we call it on- this should be Unicode too.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; unicodearr=array.array('u','Hello')\r\n&gt;&gt;&gt; unicodearr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;u&#8217;, &#8216;Hello&#8217;)<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; unicodearr.fromunicode(' world')\r\n&gt;&gt;&gt; unicodearr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;u&#8217;, &#8216;Hello world&#8217;)<\/div>\n<h4 class=\"western\">8. array.index(x) in Python<\/h4>\n<p>This returns the index for the first occurrence of <i>x<\/i> in the Python array.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr=array.array('i',[1,3,2,4,3,5])\r\n&gt;&gt;&gt; arr.index(3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<\/div>\n<h4 class=\"western\">9. array.insert(I,x) in Python<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.insert(2,7)\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [1, 3, 7, 2, 4, 3, 5])<\/div>\n<p>This inserts the element 7 at index 2.<\/p>\n<h4 class=\"western\">10. array.pop(i) in Python<\/h4>\n<p>This lets us drop the element at the position i.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.pop(2)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<\/div>\n<h4 class=\"western\">11. array.remove(x) in Python<\/h4>\n<p>This will let you remove the first occurrence of an element from the Python array.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.remove(3)\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [1, 2, 4, 3, 5])<\/div>\n<h4 class=\"western\">12. array.reverse() in Python<\/h4>\n<p>This reverses the Python array.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.reverse()\r\n&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [5, 3, 4, 2, 1])<\/div>\n<h4 class=\"western\">13. array.tobytes() in Python<\/h4>\n<p>This returns a representation in bytes of the values of the array in Python.<\/p>\n<p>This is the same as array.tostring(), which is deprecated.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.tobytes()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">b&#8217;\\x05\\x00\\x00\\x00\\x03\\x00\\x00\\x00\\x04\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x01\\x00\\x00\\x00&#8242;<\/div>\n<h4 class=\"western\">14. array.tolist() in Python<\/h4>\n<p>This converts the array into a list.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr.tolist()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[5, 3, 4, 2, 1]<\/div>\n<h4 class=\"western\">15. array.tounicode() in Python<\/h4>\n<p>This converts an array to a Unicode string. You need a Unicode array for this.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; unicodearr.tounicode()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Hello world&#8217;<\/div>\n<h3 class=\"western\">Python Array &#8211; More Information<\/h3>\n<p>Python Arrays are space-efficient collections of numeric values that are uniformly-typed. You can:<\/p>\n<div id=\"attachment_22151\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Extra-Information-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-22151\" class=\"wp-image-22151 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Extra-Information-01.jpg\" alt=\"Python Array - More Information\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Extra-Information-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Extra-Information-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Extra-Information-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Extra-Information-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Extra-Information-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-22151\" class=\"wp-caption-text\">Python Arrays Module &#8211; More Information<\/p><\/div>\n<h4 class=\"western\">1. How to Index an Array in Python?<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [5, 3, 4, 2, 1])<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr[1]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">3<\/div>\n<h4 class=\"western\">2. Slice an array<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr[1:4]\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [3, 4, 2])<\/div>\n<h4 class=\"western\">3. Concatenate two arrays in Python<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr+arr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [5, 3, 4, 2, 1, 5, 3, 4, 2, 1])<\/div>\n<h4 class=\"western\">4. Multiply an array by a constant<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; arr*2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">array(&#8216;i&#8217;, [5, 3, 4, 2, 1, 5, 3, 4, 2, 1])<\/div>\n<p>So, this was all about Python Arrays Tutorial. Hope you like our explanation<\/p>\n<h3>Python Interview Questions on Array Module<\/h3>\n<p>1. What is array module in Python?<\/p>\n<p>2. How do you display an array in Python?<\/p>\n<p>3. How to use an array module in Python?<\/p>\n<p>4. What is the difference between array and list in Python?<\/p>\n<p>5. How to read an array in Python?<\/p>\n<h3 class=\"western\">Conclusion<\/h3>\n<p>The array module offers a typed, compact sequence of primitive values like signed ints or floats, stored in C style without the overhead of full Python objects.<\/p>\n<p>Converting between arrays and lists is a single call, so you can crunch numbers quickly then return friendly Python objects to other parts of the program. Using arrays also avoids accidental mixed types that break math. Remember that array does not auto-grow as smoothly as lists for large datasets, so pre-size when possible to reduce reallocations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today in this Python Array Tutorial, we will learn about arrays in Python Programming. Here, we will discuss how Python array import module and how can we create Array. Along with this, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":22152,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[1117,6646,10367,10368,10369,10371,10372,10373,10375,15536],"class_list":["post-22134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-array-in-python","tag-importing-the-module","tag-python-array-append","tag-python-array-class","tag-python-array-class-methods","tag-python-array-example","tag-python-array-index","tag-python-array-module","tag-python-array-tutorial","tag-what-is-a-python-array"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Array Module - How to Create and Import Array in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn What is Array in Python and how to create it with examples, Importing Module in Python Array, array class data Items\" \/>\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-array-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Array Module - How to Create and Import Array in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn What is Array in Python and how to create it with examples, Importing Module in Python Array, array class data Items\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-array-module\/\" \/>\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-07-20T21:30:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-22T09:55:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Module-01.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 Array Module - How to Create and Import Array in Python - DataFlair","description":"Learn What is Array in Python and how to create it with examples, Importing Module in Python Array, array class data Items","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-array-module\/","og_locale":"en_US","og_type":"article","og_title":"Python Array Module - How to Create and Import Array in Python - DataFlair","og_description":"Learn What is Array in Python and how to create it with examples, Importing Module in Python Array, array class data Items","og_url":"https:\/\/data-flair.training\/blogs\/python-array-module\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-07-20T21:30:55+00:00","article_modified_time":"2026-04-22T09:55:01+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Module-01.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-array-module\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Array Module &#8211; How to Create and Import Array in Python","datePublished":"2018-07-20T21:30:55+00:00","dateModified":"2026-04-22T09:55:01+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/"},"wordCount":966,"commentCount":6,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Module-01.jpg","keywords":["Array in Python","Importing the Module","python array append","Python Array Class","Python Array Class Methods","python array example","python array index","Python Array Module","python array tutorial","What is a Python Array"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-array-module\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/","url":"https:\/\/data-flair.training\/blogs\/python-array-module\/","name":"Python Array Module - How to Create and Import Array in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Module-01.jpg","datePublished":"2018-07-20T21:30:55+00:00","dateModified":"2026-04-22T09:55:01+00:00","description":"Learn What is Array in Python and how to create it with examples, Importing Module in Python Array, array class data Items","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-array-module\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Module-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-Array-Module-01.jpg","width":1200,"height":628,"caption":"Python Array Module - Data Items &amp; Modules"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-array-module\/#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 Array Module &#8211; How to Create and Import Array in Python"}]},{"@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\/22134","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=22134"}],"version-history":[{"count":13,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/22134\/revisions"}],"predecessor-version":[{"id":147772,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/22134\/revisions\/147772"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/22152"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=22134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=22134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=22134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}