Arrays Grade8 Notes
Arrays Grade8 Notes
3. Explain how you can sort an array {67, 23, 98, 19} using Python?
Ans. Numbers=[67,23,98,19]
Numbers.sort()
print(Numbers)
Output: [19,23,67,98]
Output : 4
5. Find the array length, first index and last index of the given integer array.
1 2 3 4 5
Output: 3,5,8,10
8. What is searching in an array?
Ans. Searching in array means to find a particular element in the array. Python
uses indexing as a method to search for an element in an array.
Eg :
X=[“a”, “b”, “c”, “d”, “e”]
print(x.index(“d”))
Output: 3
9. What is bubble sort? write a python program to sort an array.Ans. Bubble sort
is a method of sorting that works by repeatedly swapping adjacent elements if
they are in incorrect order.
Program :
def sort(nums):
for i in range(len(nums)-1,0,-1):
for j in range(i):
if nums[j]>nums[j+1]:
temp=nums[j]
nums[j]=nums[j+1]
nums[j+1]=temp
nums=[8,7,3,10,2,9]
sort(nums)
print(nums)