[go: up one dir, main page]

0% found this document useful (0 votes)
30 views1 page

Coding L4

Arrays are collections of similar data types that can store multiple values referenced by a single name. Arrays are indexed starting from 0. Python has built-in functions to sort arrays in ascending order and search for values using their index.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Coding L4

Arrays are collections of similar data types that can store multiple values referenced by a single name. Arrays are indexed starting from 0. Python has built-in functions to sort arrays in ascending order and search for values using their index.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Coding L4: -

1. What are arrays in programming?


Arrays are collection of similar data type variables. Array can store multiples values which
can be referenced by single name. Arrays are always stores in specific memory location.
Arrays do not support different data types in same collection.

2. Explain how arrays are indexed in programming.


The variables in an Array are always ordered sequentially with index starting with 0.

Example: Array with variables of Integer Data Type stored in it.

Here, Length of Array = 6

First Index = 0

Last Index = 5

3. Explain how you can sort an array {67, 23, 98, 19} using Python?
Sorting is the process of ordering items in a collection. Python has inbuilt sort function to
order an array. The sort () method sorts the list ascending by default.
Numbers = [67, 23, 98, 19]

Numbers Sort ()

Print (Numbers)

Output: [19, 23, 67, 98]

4. How do you search a particular value from an array in Python?


Python uses indexing as a method to search for an element in an array. For Example –

X = [34,45,3,23,22,78,65]

Print(X.index(23))

If you run the above code, you would get 3 as output. As 23 is located on index 3.

You might also like