ARRAYS
1. What is an array?
Collection of elements of same datatype
Very similar to lists in python
To create an array, use array function by importing array module
2. How to create an array?
Using from keyword
Using array function by importing array module
Eg: from array import array
a=array(‘i’,[5,2,7,1])
3. Define type code
Eg: a=array(‘i’,[5,2,7,1])
Here, we create array of integer type
Here, ‘i’ is type code
Type code determines type of array during creation
i = int, f=float, d=double(float having many decimal points)
4. How to access elements from array
Using indexing to access single element and slicing to access multiple elements
5. How to change elements in array?
Array is mutable(can be modified)
We can change elements by first accessing an element, then changing it to desired
element
6. How to add elements in array?
append() -> adds single element to array at end
extend() -> adds multiple elements to end of array
insert() -> adds element at desired position
7. what are operators in array?
Concatenation(+) – merges 2 arrays together
Repitation(*) – repeats elements in array desired number of times
8. How to remove elements from array?
pop() – removes element from specified index or if not specified, removes last
element
remove() – removes specified element
del – deletes specified index or if not specified, deletes entire array