Storage and Use of Arrays 1

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:45 PM on 3/11/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

14 Terms

1
New cards

What are arrays?

  • a fundamental data structure, and an important part of most programming languages.

  • In Python, they are containers that can store more than one item at the same time.

  • an ordered collection of elements with every value being of the same data type.

  • they can only hold a sequence of multiple items that are of the same type

2
New cards

three ways to import array module

  • array.array()

  • arr.array()

  • array()

  • for printing arrays: for i in range ()

import array
import array as arr
from array import

for i in range ()

3
New cards

defining arrays in python

variable_name = array(typecode,[elements])
  • List of type code to define Arrays in Python

4
New cards

typecodes

knowt flashcard image
5
New cards

create arrays with a float typecode

import array as arr
b = arr.array('d', [2.5, 3.2, 3.3])
print(b)

6
New cards

If you want to print original copy

for i in range (0, 3):
    print(b[i])

2.5
3.2
3.3

7
New cards

creating an array with integer type

import array as arr
a = arr.array('i', [1,2,4])
print(a)

array('i', [1, 2, 4])

8
New cards

adding elements to an array

  • insert(position, value)

  • append()

9
New cards

insert(position, element)

a.insert(1,4)
print(a)

array('i', [1, 4, 2, 3])

10
New cards

append(element)

import array

s1 = array.array('i', [1,2,3])
s2 = array.array('i', [4,5,6])
print(s1)
print(s2)
s3 = s1 + s2
print(s3)
s1.append(4)
print(s1)

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

11
New cards

Accessing the elements from an Array

  • can access the elements of an array using the index operator [ ]

import array as arr

a = arr.array('i', [1, 2, 3, 4, 5, 6])
print("Access element is: ", a[0])      
print("Access element is: ", a[3])    
b = arr.array('d', [2.5, 3.2, 3.3])
print("Access element is: ", b[1])
print("Access element is: ", b[2])

Access element is:  1
Access element is:  4
Access element is:  3.2
Access element is:  3.3

12
New cards

Remove the elements from an Array

import array
x = array.array('i', [1,2,3,1,5])
print("The new created array is : ")
for i in range (0,5):
    print(x[i])

The new created array is : 
1
2
3
1
5

13
New cards

Remove the elements from an Array using pop(position) function

print("The popped element is : ")
print(x.pop(2))

print("The array after popping is : ")
for i in range (0,4):
    print(x[i])

The popped element is : 
3
The array after popping is : 
1
2
1
5

14
New cards

Remove the elements from an Array using remove(position) function

x.remove(1)
print("The array after removing is : ", end ="")
for i in range (0,3):
    print (x[i])

The array after removing is : 2
1
5

Explore top notes

Explore top flashcards

flashcards
BIS Final Acronyms
40
Updated 836d ago
0.0(0)
flashcards
Filmgeschiedenis 2 (2022-2023)
134
Updated 1014d ago
0.0(0)
flashcards
Tema 2B: ¿Quién Soy Yo?
65
Updated 68d ago
0.0(0)
flashcards
civil war
25
Updated 1223d ago
0.0(0)
flashcards
Elbow and Forearm
54
Updated 734d ago
0.0(0)
flashcards
BIS Final Acronyms
40
Updated 836d ago
0.0(0)
flashcards
Filmgeschiedenis 2 (2022-2023)
134
Updated 1014d ago
0.0(0)
flashcards
Tema 2B: ¿Quién Soy Yo?
65
Updated 68d ago
0.0(0)
flashcards
civil war
25
Updated 1223d ago
0.0(0)
flashcards
Elbow and Forearm
54
Updated 734d ago
0.0(0)