Accessing and storing data in an array
Accessing and storing data in an array
and
storing
data in an
array.
B y : A f u a , C h a rly n
and Rohan.
Key words
vIndex: Is a numerical position that identifies each element.
vElement: A single value or item stored within the array.
vAssignment: An operation where a value is stored in a array.
vAppend: To add something to the end
What is an array?
An array is a data structure that contains
a group of elements of the same data
type and stores them together in
contiguous memory locations. Since an
array stores its values in contiguous
memory locations, the size of an array is
set when created.
Example of an array
Key words:
Index: The number that
represents the data item
you access.
Examples;5,4,3,2,1,0
Elements: The data type
stored in the array.
Examples;7,8,5,0
How to access data in an array
How to Access Array Elements:
1.Use the element's index (position number) to access
it.
2. Indexing starts at 0 (first element).
Example of accessing data in an
array
For example we have an array [Apple,Banana,Cherry]
and you want to access Apple it will be
myArray=[0]
This will access the element with that index which is
Apple.
Storing data in an array
The data that is going to be stored
is in an empty list. Example;
array=[]
This will create an empty list.
Data can be stored with an
individual element. For example
this code will store 4 in index 0:
array[0]=4
Adding to the list
If you want to store 9 numbers but
there is no index 8. For example that
number you want to store is 6, you
can use append. Then 6 can be
added at the end of the list:
mylistArray=[]
mylistArray.append(6)
Thank you for listening
Keep exploring!