Other than some generic containers like list, Python in its definition can also handle containers with specified data types. Array can be handled in python by module named “array“. They can be useful when we have to manipulate only a specific data type values.
Operations on Array :
1. array(data type, value list) :- This function is used to create an array with data type and value list specified in its arguments. Some of the data types are mentioned in the table below.
|Type Code||C Type||Python Type||Minimum size in Bytes|
|‘q’||signed long long||int||8|
|‘Q’||unsigned long long||int||8|
2. append() :- This function is used to add the value mentioned in its arguments at the end of the array.
3. insert(i,x) :- This function is used to add the value at the position specified in its argument.
The new created array is : 1 2 3 The appended array is : 1 2 3 4 The array after insertion is : 1 2 5 3 4
4. pop() :- This function removes the element at the position mentioned in its argument, and returns it.
5. remove() :- This function is used to remove the first occurrence of the value mentioned in its arguments.
The new created array is : 1 2 3 1 5 The popped element is : 3 The array after popping is : 1 2 1 5 The array after removing is : 2 1 5
6. index() :- This function returns the index of the first occurrence of value mentioned in arguments.
7. reverse() :- This function reverses the array.
The new created array is : 1 2 3 1 2 5 The index of 1st occurrence of 2 is : 1 The array after reversing is : 5 2 1 3 2 1
This article is contributed by Manjeet Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Mathematical Functions in Python | Set 2 (Logarithmic and Power Functions)
- Mathematical Functions in Python | Set 1 (Numeric Functions)
- Virtual Functions and Runtime Polymorphism in C++ | Set 1 (Introduction)
- Array in Python | Set 2 (Important Functions)
- Python | Set 2 (Variables, Expressions, Conditions and Functions)
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Calendar Functions in Python | Set 1( calendar(), month(), isleap()...)
- Operator Functions in Python | Set 1
- Ceil and Floor functions in C++
- Pure Virtual Functions and Abstract Classes in C++
- Functions in C/C++
- Inline Functions in C++
- Python Language Introduction
- An introduction to Flowcharts
- Introduction of Microprocessor
- Introduction of Secondary Memory
- Introduction of Object Oriented Programming
- Python | Set 4 (Dictionary, Keywords in Python)
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)