GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PythonScript/DataStructureAndAlgorithm/Array.md at master · chavarera/PythonScript

Expand file tree

/

Array.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
62 lines (50 loc) · 1.58 KB
/

Array.md

Copy path

File metadata and controls

62 lines (50 loc) · 1.58 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Array

Introduction

  • The array is the most commonly used data structure in most of the programming languages.
  • The collection of elements of the same data types grouped together called is an array.
  • All elements of an array must be of the same datatypes.
  • We can create an array in python by importing an array module.
  • In Python list treated as an array but the list contains a different type of element inside it where array support only a single type of element to be stored in it.

How to create Array?

First import array module as follows

import array

Create an array using array module

array=array.array('singletypecode',[element of similar data types])
  • If you pass different type element to array it will generate an error
  • Arrays represent basic values and behave very much like lists

Applications of An Array

  1. lookup table
  2. hash table
  3. heaps

Advantages of an Array

  • Very easy to implement and use.
  • Fast data structure
  • Any item from any position can be accessed because of indexes are present in an array
  • arrays can have as many dimensions as we want
  • The size of the array can be changed dynamically.

Disadvantages of an Array

  • Store only similar data types item in the array

Examples:

#import array module
import array

#Create a integer elements array
arr=array.array('i',[1,2,3,4,5,6,7])

#print array
print("Normal Array")
print(arr)

#print type of an array
print("\n Type of an Array")
print(type(arr))

Output:

Normal Array
array('i', [1, 2, 3, 4, 5, 6, 7])

 Type of an Array
<class 'array.array'>
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.