Implementation of array in Python
- Initializes a Python list arr with values.
- Accesses the element at index 1 using arr[1] and prints its value.
- Modifies the element at index 1 by assigning a new value (12) to arr[1] and prints the modified value.
Python3
arr = [ 1 , 2 , 3 , 4 , 5 ] # Initializing an array with values # Accessing elements print ("Element at index 1 :", arr[ 1 ]) # Modifying elements arr[ 1 ] = 12 print ("Modified element at index 1 :", arr[ 1 ]) |
Output
Element at index 1: 2 Modified element at index 1: 12
Implement Arrays in different Programming Languages
Arrays are one of the basic data structures that should be learnt by every programmer. Arrays stores a collection of elements, each identified by an index or a key. They provide a way to organize and access a fixed-size sequential collection of elements of the same type. In this article, we will learn about the basic use of array in most common languages like C, C++, Java, Python, etc.
Table of Content
- What is an Array?
- Implementation of array in C++:
- Implementation of array in C:
- Implementation of array in Java:
- Implementation of array in Python:
- Implementation of array in C#:
- Implementation of array in JavaScript:
- Pros and Cons of array: