[go: up one dir, main page]

0% found this document useful (0 votes)
2 views3 pages

Collection and Arrays 1

This document provides an overview of arrays in programming, explaining their definition, indexing, sorting, and searching methods in Python. It includes examples of how to sort an array and check for the presence of a value. Additionally, it illustrates a real-world application of arrays in managing student scores efficiently.

Uploaded by

vaibhavsinghh24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Collection and Arrays 1

This document provides an overview of arrays in programming, explaining their definition, indexing, sorting, and searching methods in Python. It includes examples of how to sort an array and check for the presence of a value. Additionally, it illustrates a real-world application of arrays in managing student scores efficiently.

Uploaded by

vaibhavsinghh24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CLASS 8

CHAPTER – 6
UNDERSTANDING ARRAYS
NOTES
1. What are Arrays in programming?
Arrays are a data structure that allows you to store multiple items in a single variable,
similar to lists in standard Python. They can hold elements of the same type, such as
integers, floats, or strings, and are used to manage collections of data efficiently.

2. Explain how arrays are indexed in programming?


Arrays are indexed using integer values that represent the position of elements within the array.
Indexing allows you to access, modify, or delete individual elements of an array.

For example, consider an array:


array = [10, 20, 30, 40, 50]
array[0] refers to 10 (the first element).
array[1] refers to 20 (the second element).
array[4] refers to 50 (the fifth element).

3. Explain how you can sort an array {67, 23, 98, 19} using python.
To sort an array [67, 23, 98, 19] in Python, you can use the sort( ) method of a list.
# Original array
array = [67, 23, 98, 19]
# Using sort( ) method to sort the array in place
array.sort( )

print("Sorted Array:", array)


Output:
Sorted Array: [19, 23, 67, 98]
4. How do you search for a particular value from an array in python?
To search for a particular value in an array in Python,
1. Using the in Operator ‘in’ :
This is the method to check if a value exists in the array.
# Define the array
array = [67, 23, 98, 19]
# Search for a value, e.g., 23
if 23 in array:
print("23 is present in the array")
else:
print("23 is not present in the array")
Output:
23 is present in the array

2. Using the index() Method:


The index() method returns the index of the first occurrence of the specified value. If
the value is not found, it raises a ValueError.
# Define the array
array = [67, 23, 98, 19]
# Get the index of the value 98
index = array.index(98)
print(“98 is present at index”, index)
Output:
98 is present at index 2
5. Describe a real-world scenario where using an array would help organize and
manage data efficiently.
Using arrays can be highly beneficial in numerous real-world scenarios where
managing and organizing data efficiently is crucial.

For example: Managing Student Scores in a Class


Imagine a teacher wants to keep track of the test scores for 30 students in a class.
Using an array is an efficient way to store and manage this data.
Arrays can Organize Data:
An array can be used to store the scores of all 30 students in a single data structure.
For example, an array named scores can hold each student's test score:
scores = [85, 90, 78, 88, 92, 75, 83, 95, 80, 70, 89, 87, 76, 93, 81, 77, 84, 82, 91, 79,
94, 86, 74, 69, 96, 99, 65, 68, 72, 100]
To sort the scores in ascending order
Scores.sort( )

You might also like