🔰Array in Python..

Introduction and Function

What is an “Array” ?

Array is the collection of elements of similar data type stored in a single variable.

Following are the some data types and space require them in bytes.

char => 1

int => 2

short int =>2

long int =>4

long long int =>8

float =>4

double =>8

Operations on Array :

1.array(data type, value list) :- This function is used to create an array with data type and value list specified in its arguments.

OUTPUT =>The new created array is: 1 2 3 7 8 9

2.append():- This function is used to add the value mentioned in its arguments at the end of the array.

OUTPUT =>The appended array is: 1 2 3 7 8 9 4

3.insert(i,x) :- This function is used to add the value(x) at the i th position specified in its argument.

OUTPUT =>The array after insertion is: 1 2 5 3 7 8 9 4

4.pop():- This function removes the element at the position mentioned in its argument and returns it.

OUTPUT =>The popped element is : 5
The array after popping is : 1 2 3 7 8 9 4

5.remove():- This function is used to remove the first occurrence of the value mentioned in its arguments.

OUTPUT =>The array after removing is : 2 3 7 8 9 4

6.index():- This function returns the index of the first occurrence of value mentioned in arguments.

OUTPUT =>The index of 1st occurance of 2 is: 0

7.reverse():- This function reverses the array.

OUTPUT =>The array after reversing is: 4 9 8 7 3 2

Hope this blog is helpful to you to clear your concepts..😉🙌

Thanks for reaching here…!!😊

--

--

Computer Engineer 👩🏼‍💻

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store