Page 54 - Touchcode_C8_Flipbook
P. 54

4               PROGRAMMING WITH ARRAYS












                          Learning Outcomes

                       Introduction                                       What are Arrays?
                       Playing with Colors                                Sorting an Array

                       Searching in an Array                               Using Python  to Arrange an Array in
                                                                          Ascending  Order  using  Bubble  Sort  in
                                                                          MakeCode



                  INTRODUCTION
                  An array is an arrangement of objects. Have you seen an egg box? In an egg box, the eggs

                  are arranged in a rectangular fashion. This is an array.

                  If you wish to save a contact number on our phone. The contact app on your phone contains
                  a lot of contacts. They are stored in the form of an array. When you add or delete a contact
                  in our phone, this is same as adding or deleting elements in an array. So in this chapter, you
                  will learn more on arrays, sorting-searching of an array and to apply the concept of arrays
                  in block coding and Python by using some fun examples.


                  WHAT ARE ARRAYS?
                  An array is a collection of similar data type variables. Arrays do not support different data

                  types. For example, you can make an array of Integers and another array of Strings, but
                  cannot make an array having Integer and Strings in the same collection.

                  Books in a library, is an example of arrays where all the shelves have a common data type
                  (read – book) in it.

                  Advantage of the array is that it improves the readability of code by using a single variable
                  for a large set of data. But there are limitations of array also, which are:

                      You can only store variables with the same data types in an array.
                      The variables  in  an  array are  always  ordered  sequentially  with the  index starting
                      from 0.
                      Arrays are always static and fixed in length and size.









                   52     Touchcode-VIII
   49   50   51   52   53   54   55   56   57   58   59