GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — Python Arrays - GeeksforGeeks Python ArraysLast Updated : 19 Sep, 2026 Python provides multiple ways to work with linear data structures, which store elements sequentially. Although Python does not have a built-in array type like some other languages, similar functionality can be achieved using: ListsLists are a flexible and commonly used data structure for storing elements in sequence. Unlike arrays in other languages, list:
Output [1, 'Hello', [3.14, 'world'], 2] NumPy ArraysNumPy arrays are a part of NumPy library, which is a tool for numerical computing. Designed for high-performance operations on large datasets and support multi-dimensional arrays and matrices, making them suitable for complex mathematical computations.
Output [2 4 6 8] [[2 4] [6 8]]
ArraysArray is a collection of elements stored at contiguous memory locations, used to hold multiple values of the same data type. Unlike Lists, which can store mixed types, arrays are homogeneous and require a typecode during initialization to define the data type.
Output 1
array('i', [1, 2, 3, 5])
Explanation: parameter 'i' is the typecode, it tells Python to treat the elements as signed integers ([1, 2, 3]) of a specific byte size (usually 2 or 4 bytes). The following table outlines standard typecodes, their mapped C types and minimum memory requirements:
Create an ArrayArray can be created by importing an array module. array(data_type, value_list) is used to create array with data type and value list specified in its arguments.
Output 1 2 3 ![]() Adding ElementsElements can be added to an array using insert() to place a value at a specific index, or append() to add a value at the end.
Output 1 2 3 1 4 2 3
Accessing ItemsArray elements are accessed using their index with square brackets [ ]. Each item has a position starting from 0 and the index must be an integer.
Output 1 4 3.2 3.3 Removing ElementsElements can be removed using remove(), which deletes the first occurrence of a value or pop(), which removes and returns an element (last by default or a specific index if provided).
Output array('i', [2, 3, 1, 5])
array('i', [2, 3, 5])
SlicingSlicing is used to access a specific range of elements from an array using index positions. ![]()
Output array('i', [4, 5, 6, 7, 8])
array('i', [6, 7, 8, 9, 10])
array('i', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Searching ElementIn order to search an element in the array we use index() method. This function returns the index of the first occurrence of value mentioned in arguments.
Output 1 0 Updating ElementsIn order to update an element in the array we simply reassign a new value to the desired index we want to update.
Output array('i', [1, 2, 6, 1, 2, 5])
array('i', [1, 2, 6, 1, 8, 5])
Operations on Array1. Counting Elements: We can use count() method to count given item in array.
Output 3 2. Reversing Elements: In order to reverse elements of an array use reverse method.
Output 5 4 3 2 1 3. Extend Element: extend() function is used to attach an item from iterable to the end of the array. This method is used to add an array of values to the end of a given or existing array.
Output array('i', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Comment Explore | ||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |