0
0
DSA Pythonprogramming~5 mins

Array Declaration and Initialization in DSA Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an array in simple terms?
An array is like a row of boxes where each box can hold a value. All boxes are the same size and arranged one after another.
Click to reveal answer
beginner
How do you declare an array of 5 integers in Python?
You can declare it using a list like this: arr = [0, 0, 0, 0, 0]. This creates 5 boxes holding 0 initially.
Click to reveal answer
beginner
What does 'initialization' mean when working with arrays?
Initialization means putting starting values into the array boxes right after creating them.
Click to reveal answer
beginner
Show how to declare and initialize an array with values 1, 2, 3, 4, 5 in Python.
Use arr = [1, 2, 3, 4, 5]. This creates an array with 5 boxes holding those numbers.
Click to reveal answer
beginner
Can arrays in Python change size after creation?
Yes, Python lists (arrays) can grow or shrink by adding or removing elements, unlike fixed-size arrays in some other languages.
Click to reveal answer
Which of these is a correct way to declare an array of 3 zeros in Python?
Aarr = {0, 0, 0}
Barr = (0, 0, 0)
Carr = [0, 0, 0]
Darr = [0] * 3
What is the index of the first element in a Python array?
A1
B0
C-1
DDepends on the array size
How do you create an array with values 5, 10, 15 in Python?
Aarr = [5, 10, 15]
Barr = (5, 10, 15)
Carr = {5, 10, 15}
Darr = 5, 10, 15
What happens if you try to access an index outside the array size in Python?
AYou get an error
BIt returns None
CIt returns 0
DIt returns the last element
Which of these is NOT a way to initialize an array in Python?
Aarr = [1, 2, 3]
Barr = list((1, 2, 3))
Carr = {1, 2, 3}
Darr = [0] * 3
Explain how to declare and initialize an array with 4 elements in Python.
Think about using square brackets and putting values inside.
You got /3 concepts.
    Describe what happens when you try to access an array element by index in Python.
    Remember how Python counts positions and what happens if you go too far.
    You got /3 concepts.