Programming With Arrays - Grade 8
Programming With Arrays - Grade 8
What is a an Array?
An array is declared by giving the name, size and type of data it holds
Declaration of Array:
DECLARE name_of_athe_array : ARRAY[size_of_the_array] OF DATATYPE
Example:
Declaring an array called Names that stores names of 10 students
DECLARE Names : ARRAY[10] OF STRING
What is a List in Python?
● List is a sequence of values called items or elements
● The elements can be of any data type
● Creating a list is as simple as putting different comma-separated values
between square brackets.
For example −
Subjects = ['physics', 'chemistry', ‘Biology’]
Subjects is a list that contains three elements
Marks = [56,90,45,56.67,34,89.8]
Marks is a list that contains 6 elements
Using Lists you can store values and retrieve them anywhere in
your program
Accessing elements inside an array
Elements inside an array can be accessed using their index
Index is the position of an element inside an array
We use the square brackets [ ] with the index inside to obtain value available at that
index.
Index always starts from 0 and ends at n-1 - n being the size of the list
Example:
Consider the following list
Subjects = [‘Physics’ , ‘Chemistry’, ‘Computer Science’ , “Mathematics’ , ‘Biology’]
Index - 0 1 2 3 4