Python Array

The array is a data structure that holds more than one value at a time.

In the core python list also treated as an array.

In data science, Numpy is used as an array.

 

Basic python syntax to declare an array in python:

>>> a = arr.array(‘d’, [‘a’, ‘b,’, ‘c’])

The first argument shows an array ‘data-type’ and second is a list of values.

List of array data types

Here we create a simple list of array data types:

  •  I, i, h, H  - Use for “int”, size is 3(in bytes

  •  f - Use for “float”, size is 4(in bytes)

  • - Use for “float”, size is 4(in bytes)

How to access array element

We can access array element simple way – as per index value

>>> a[0]

Finding the length of array

Array length can be find using the len() funcition.

>>> x = len(a)

Array with loop

Element of array can be find using the loop, like list or dict. 

>>> for x in a:
         print(x)

Adding the element to the array

Element can be added in the array using the "append"

Example:

>>> a.append("i")

Removing the element from array array

Element can be removed from the array using the pop()

Example:

>>> a.pop(1)

It removes the second element from the array.

We can also remove the element from the array using "remove"

>>> a.remove("b")

Other array methods which are useful and most important

Here the list of array methods which is most important:

append()clear()copy()count(), extend(), index(), insert()sort()reverse(), etc.

Contact Us

Tel: (+91) 0120  4118730  

Time :   10 : 00  AM -  08 : 00 PM IST 

Registered address: G-69, Sector 63, 

 Noida - 201301, India

We Provide Services Across The different countries

USA    Australia   Canada   UK    UAE    Singapore   New Zealand    Malasia   India   Ireland   Germany

CodersArts is a Product by Sofstack Technology Solutions Pvt. Ltd.

  • CodersArts | Linkedin
  • Instagram