{"id":1477,"date":"2023-05-21T08:26:24","date_gmt":"2023-05-21T08:26:24","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=1477"},"modified":"2023-05-21T08:26:24","modified_gmt":"2023-05-21T08:26:24","slug":"explain-arrays-in-pythons-with-example","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/21\/explain-arrays-in-pythons-with-example\/","title":{"rendered":"Explain arrays in Pythons with example"},"content":{"rendered":"\n<p>A\u00a0Python Array\u00a0is a collection of a common type of data structures having elements with the same data type. It is used to store collections of data. In Python programming, arrays are handled by the \u201carray\u201d module. If you create arrays using the array module, elements of the array must be of the same numeric type.<\/p>\n\n\n\n<p><strong>Syntax to Create an Array in Python<\/strong><\/p>\n\n\n\n<p>You can declare an array in Python while initializing it using the following syntax.<br><code>arrayName = array.array(type code for data type, [array,items])<\/code><\/p>\n\n\n\n<ol>\n<li><strong>Identifier<\/strong>: specify a name like usually, you do for variables<\/li>\n\n\n\n<li><strong>Module<\/strong>: Python has a special module for creating array in Python, called \u201carray\u201d \u2013 you must import it before using it<\/li>\n\n\n\n<li><strong>Method<\/strong>: the array module has a method for initializing the array. It takes two arguments, type code, and elements.<\/li>\n\n\n\n<li><strong>Type Code<\/strong>: specify the data type using the type codes available (see list below)<\/li>\n\n\n\n<li><strong>Elements<\/strong>: specify the array elements within the square brackets, for example [130,450,103]<\/li>\n<\/ol>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import array as myarray\nabc = myarray.array('d', [2.5, 4.9, 6.7])<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A\u00a0Python Array\u00a0is a collection of a common type of data structures having elements with the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1477"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=1477"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1477\/revisions"}],"predecessor-version":[{"id":1478,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1477\/revisions\/1478"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=1477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=1477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=1477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}