Mastering Python Data Structures

Mastering Python Data Structures

University

10 Qs

quiz-placeholder

Similar activities

OOPS quiz-1

OOPS quiz-1

University

10 Qs

Examen Teórico Extraordinario de Programación con C

Examen Teórico Extraordinario de Programación con C

University

10 Qs

Tut 8 - Prog2 - Collections und Monaden

Tut 8 - Prog2 - Collections und Monaden

University

7 Qs

Python Workshop Day - 2

Python Workshop Day - 2

University

15 Qs

Python Basics

Python Basics

University

15 Qs

Python Day 9

Python Day 9

University

6 Qs

1045 week 7 (Transforming Sequences (Mutability & Memory))

1045 week 7 (Transforming Sequences (Mutability & Memory))

University

5 Qs

Python Variables

Python Variables

University

15 Qs

Mastering Python Data Structures

Mastering Python Data Structures

Assessment

Quiz

Computers

University

Hard

Created by

Solaf Ali

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What method would you use to add an element to a list in Python?

Use the 'extend()' method.

Use the 'add()' method.

Use the 'insert()' method.

Use the 'append()' method.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Explain how to create a dictionary comprehension to generate a dictionary of squares from a list of numbers.

{x: x**2 for x in numbers}

{x: x^2 for x in numbers}

{x: x*2 for x in numbers}

{x: x+1 for x in numbers}

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you slice an array to get the first three elements?

array.slice(3)

array.slice(0, 3)

array.slice(1, 4)

array.slice(0, 2)

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the difference between mutable and immutable types in Python?

Mutable types cannot be changed; immutable types can be changed after creation.

Both mutable and immutable types can be changed at any time.

Mutable types are faster than immutable types in all cases.

Mutable types can be changed; immutable types cannot be changed after creation.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you remove an item from a list by its value?

Use del list[value] to delete an item by its value.

Use list.pop(index) to remove an item by its index.

Use list.clear(value) to remove all items from the list.

Use list.remove(value) to remove an item by its value.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Write a dictionary comprehension that creates a dictionary from two lists: keys and values.

{key: values[key] for key in range(len(keys))}

{key: value for key in keys}

{key: value for key, value in zip(keys, values)}

{key: values[key] for key in keys}

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following code: arr = [1, 2, 3, 4]; print(arr[1:3])?

[2, 3]

[1, 2]

[1, 2, 3, 4]

[3, 4]

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?