0
0
Data Analysis Pythondata~5 mins

Array indexing and slicing in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is array indexing?
Array indexing is the way to access a single element in an array using its position number, starting from zero.
Click to reveal answer
beginner
How do you slice an array in Python?
Slicing means taking a part of an array by specifying a start and end position like array[start:end]. It gives a new array with elements from start up to but not including end.
Click to reveal answer
intermediate
What does negative indexing do in arrays?
Negative indexing counts from the end of the array. For example, -1 means the last element, -2 means the second last, and so on.
Click to reveal answer
intermediate
Explain the slice notation array[start:end:step].
This notation lets you pick elements from start to end (not including end) by skipping elements according to step. For example, step=2 picks every second element.
Click to reveal answer
beginner
What happens if you omit start or end in slicing?
If start is omitted, slicing starts from the beginning. If end is omitted, slicing goes to the last element. For example, array[:3] means from start to index 2.
Click to reveal answer
What is the index of the first element in a Python array?
A0
B1
C-1
DDepends on the array
What does array[2:5] return?
AElements at positions 2, 3, 4, and 5
BElements at positions 2, 3, and 4
CElements at positions 3, 4, and 5
DElements at positions 0 to 5
What does negative index -1 mean in an array?
ASecond last element
BFirst element
CSecond element
DLast element
What will array[::2] do?
ASelect every second element starting from the second
BSelect every element
CSelect every second element starting from the first
DSelect elements in reverse order
If you want to slice from the start to index 4, which is correct?
Aarray[:5]
Barray[0:4]
Carray[1:5]
Darray[5:]
Describe how to access the last three elements of an array using slicing.
Think about counting from the end with negative numbers.
You got /3 concepts.
    Explain the difference between array indexing and slicing with examples.
    Indexing gets one item, slicing gets a part of the array.
    You got /3 concepts.