VOOZH about

URL: https://www.geeksforgeeks.org/python/array-in-python-set-2-important-functions/

⇱ Array in Python | Set 2 (Important Functions) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Array in Python | Set 2 (Important Functions)

Last Updated : 6 Sep, 2023
Array in Python | Set 1 (Introduction and Functions)

Array in Python | Set 2

Below are some more useful functions provided in Python for arrays:

Array Typecode Function

This function returns the data type by which the array is initialized. In this example, we are using arr.typecode to find out the data type of array initialization.


Output
The datatype of array is : 
i

Array itemsize Function

This function returns the size in bytes of a single array element. In this example, we are using itemsize function to find out the size in byte of an array element.


Output
The itemsize of array is : 
4

buffer_info() in Python

Returns a tuple representing the address in which array is stored and number of elements in it. In this example, we are using buffer_info() to do the same.


Output
The buffer info. of array is : 
(140491260368688, 6)

count() in Python

Python count() function counts the number of occurrences of argument mentioned in array.

extend() in Python

This function appends a whole array mentioned in its arguments to the specified array. In this example, we are using extend() to append another array.


Output
The modified array is : 
1 2 3 1 2 5 1 2 3 

Array fromlist() Function

This function is used to append a list mentioned in its argument to end of array. In this example, we are using fromlist() to append a list to end of array.


Output
The modified array is : 1 2 3 1 2 5 1 2 3 

tolist() in Python

This function is used to transform an array into a list. In this example, we are using tolist() to convert an array to list.


Output
The new list created is : 1 2 3 1 2 5 
Comment
Article Tags:
Article Tags: