Page 56 - Touchcode_C8_Flipbook
P. 56
To modify the first item of an array, you will write:
Color[0]=“Yellow”
Example: To create an array of a sequence of integers between 0 and 11.
Solution: Begin a loop from 0 to 11.
To add an item in an array:
Append (append() is a method to add an element to an array) every item to the array.
a=[ ]
for i in range(11)
a.append(i)
print(a)
To remove an item from an array:
pop() is a method to remove an element from an array.
Colors=[“red”, “green”, “blue”]
Colors.pop(1)
print(Colors)
SORTING AN ARRAY
Sorting is the process of arranging items in a collection.
Consider an example: Have you seen how tailors arrange shirts in a cupboard, they always
keep the shirts in sorted order of size and thus when the tailor wants to place a new shirt,
he will place it at the right position very quickly by moving other shirts forward to keep the
right place for a new shirt.
44 45 46 48 43
Sorted Unsorted
Consider the following array:
4 7 1 3 5 2 6
Here, the items are not arranged in any order.
54 Touchcode-VIII

