{"id":716,"date":"2021-06-25T11:30:49","date_gmt":"2021-06-25T10:30:49","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/?page_id=716"},"modified":"2021-06-25T11:37:20","modified_gmt":"2021-06-25T10:37:20","slug":"arrays-of-records","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/higher\/arrays-of-records\/","title":{"rendered":"Arrays of Records"},"content":{"rendered":"<h1>Creating Arrays of Records<\/h1>\n<h2>Method 1 (SQA Arrays)<\/h2>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#\r\nbookList = &#x5B;Book() for b in range(20)]\r\n#\r\nbookList&#x5B;0].title = &quot;XYZ&quot;\r\nbookList&#x5B;0].year = 2001\r\nbookList&#x5B;0].price = 14.99\r\nbookList&#x5B;0].outOfPrint = False\r\n#<\/pre>\n<h2>Method 2 (Python Lists)<\/h2>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#\r\nbookList = &#x5B;]\r\n\r\nnewBook = Book(&quot;XYZ&quot;, 2001, 14.99, False)\r\nbookList.append(newBook)\r\n\r\nnewBook = Book(&quot;ABC&quot;, 1976, 13.99, True)\r\nbookList.append(newBook) \r\n#<\/pre>\n<h1>Traversing an Array of Records<\/h1>\n<h2>Method 1 &#8211; by index<\/h2>\n<pre class=\"brush: python; title: Python; notranslate\" title=\"Python\">\r\nfor b in range(len(bookList)):\r\n    str = bookList&#x5B;b].title\r\n    str += &quot;was published in &quot;\r\n    str += booklist&#x5B;b].year\r\n    print(str)\r\n<\/pre>\n<h2>Method 2 &#8211; by object<\/h2>\n<pre class=\"brush: python; title: Python; notranslate\" title=\"Python\">\r\nfor book in bookList:\r\n    str = book.title\r\n    str += &quot;was published in &quot;\r\n    str += book.year\r\n    print(str)    \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Creating Arrays of Records Method 1 (SQA Arrays) # bookList = &#x5B;Book() for b in range(20)] # bookList&#x5B;0].title = &quot;XYZ&quot; bookList&#x5B;0].year = 2001 bookList&#x5B;0].price = 14.99 bookList&#x5B;0].outOfPrint = False # Method 2 (Python Lists) # bookList = &#x5B;] newBook = Book(&quot;XYZ&quot;, 2001, 14.99, False) bookList.append(newBook) newBook = Book(&quot;ABC&quot;, 1976, 13.99, True) bookList.append(newBook) # Traversing an Array of Records Method 1 &#8211; by index for b in range(len(bookList)): str = bookList&#x5B;b].title<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/higher\/arrays-of-records\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":330,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-716","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/comments?post=716"}],"version-history":[{"count":3,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/716\/revisions"}],"predecessor-version":[{"id":721,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/716\/revisions\/721"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/pages\/330"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingpython\/wp-json\/wp\/v2\/media?parent=716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}