What are Python Arrays?

Posted by

An array is a special variable, that can hold more than one value at a time. An array can hold many values under a single name and you can access the values by referring to an index number.

Python does not have built-in support for Arrays, but python lists can be used instead.

Access the elements of an array

You refer to an array element by referring to the index number.

Get the value of the first array item:

Modify the value of the first array item:

Adding Array elements

You can use the append() method to add an element to an array.

Removing array Elements

you can use the pop() method to remove an element from the array.

you can also use the remove() method to remove an element from the array.

Looping Array Elements

You can use the for loop to print the array elements.

List of Array Methods

append(): adds an element at end of the list.

clear(): Remove all the elements from the list.

copy(): Return the copy of the list.

count(): It returns the specific element count.

index(): It returns the index of the element.

insert(): Adds an element at the specified position.

pop(): Removes the element at the specified position.

remove(): Removes the first item with the specified value.

reverse(): Reverses the order of the list.

sort(): Sorts the list.

Len(): It returns the elements count of the list.

Leave a Reply

Your email address will not be published. Required fields are marked *