Python Array With Examples

Python Array With Examples

Array in Python

Array in Python

  • Array is the collection of items having same data type with contiguous memory location.
  • There is not a built-in array in Python, but we used other structure to store data like a list.
  • To use array in python, we have to install 3rd party library like numpy.


List used as Array

  • List is the mutable type of data type in Python that store different data type of data in a square bracket. e.g [“Rushikesh”, “Sagar”, “Sayali”, 12323, 902.323]
  • Different operations can be performed on list as pop, append, reverse, len, remove etc.


Array module Installation

NumPy installation

Just type in your terminal like cmd, PowerShell or gitbash to install numpy.

pip install numpy

pip is the package manager and package installer in python.


Use of NumPy

Import numpy

Creating array with numpy

Accessing array element using index number (Positive and Negative Index number)

Arithmetic operations on Array

Looping array elements

Reversing, Removing, Finding length of array elements etc


What is Array?

Array is the data structure which store the multiple items, that items is known as elements.

Items will have same data type

Items will have consecutive memory location

Items will have unique index number starting 0 to n-1 where n means total number of items

Array may be one dimensional or two dimensional (multidimensional)


Different Terminologies Of Array

Name of array: It show the array name, when we declare the array, then that variable is the name of array

Array Element: Items or data in the array is the array element

Index: Each array element have its own unique number, which help in accessing that element

Size: Total number of element is the size of array

Memory location: Each element are stored in the computer memory device which have their own specific and unique memory address or memory location


Array Programming Example:

Example: Write a Python Program To Create a Array Using Numpy To Get 5 Number From User, Store In a Array And Find Product Of All The Number As Stored In a Array.


from numpy import *

arr = array([])

for i in range(5):

??? v = input("Element:? ")

??? arr = append(arr, v)

print(arr)





要查看或添加评论,请登录

Rushikesh J.的更多文章

  • Try and Exception in Python

    Try and Exception in Python

    Exception is the error and is an event, which occur when program statements are executing. It disrupts the flow of…

  • Python Date Object

    Python Date Object

    We can work with time and date with Python. There are two module in Python time and datetime that used to work with…

  • String Formatting WITH Problems and Solution

    String Formatting WITH Problems and Solution

    What is String Formatting? It is the way to insert custom string or variable in a text (string). Using string…

  • SET Different Methods With Examples

    SET Different Methods With Examples

    SET Method : add() Working: This method is used to add element to set. Syntax: set.

  • Python SET Comprehension With Examples

    Python SET Comprehension With Examples

    What is Comprehension? ?We create a sequence from a given sequence is called comprehension. ?Sequence means list…

  • Difference And Symmetric Difference SET Method With Exercises

    Difference And Symmetric Difference SET Method With Exercises

    SET : Difference Method Working: It return element that are present in first set but same element absent in 2nd set. if…

  • SET : Union Method With Example

    SET : Union Method With Example

    Working: Union method will exclude all the duplicate elements / items in a sets It combine all the items of two or many…

    1 条评论
  • Introduction To Python SET Data Type

    Introduction To Python SET Data Type

    SET is the collection of unordered, unchangeable and unindexable items SET is the mutable data type, because we can add…

  • Python Dictionary Methods

    Python Dictionary Methods

    Python Dictionary Method 1 : clear() Working: It used to remove all the elements from dictionary Syntax: dict.clear()…

  • Python Dictionary Comprehension

    Python Dictionary Comprehension

    What is Comprehension ?We create a sequence from a given sequence is called comprehension ?Sequence means list, tuple…

社区洞察

其他会员也浏览了