Indexing & Slicing

Indexing & Slicing

Assessment

Quiz

Information Technology (IT)

Professional Development

Medium

Created by

KSR Datavizon

Used 2+ times

FREE Resource

Student preview

quiz-placeholder

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of my_list = [1, 2, 3, 4, 5], print(my_list[-2])?

4

2

5

3

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How would you slice the first three elements from a list my_list?

my_list[1:3]

my_list[:4]

my_list[3:]

my_list[0:3]

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following code?

my_string = "Hello, World!"

print(my_string[7:12])

World

, Wor

World

World!

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you reverse a list my_list using slicing?

my_list[::-1]

my_list[0:-1]

my_list[-1:0]

my_list[1:1:-1]

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following statements is true about slicing?

Slicing modifies the original list.

Slicing can have a negative step value.

Slicing can only extract elements from start to end.

Slicing requires all three arguments: start, stop, and step.