Lists and arrays for a test

Understanding lists and arrays is crucial for organizing data in programming. This study material covers key concepts and differences between the two.

CharlotteBrown·15 flashkort·12 spørsmål·13 visninger
high schoolcomputer_scienceprogramming
0
Kjent
1 / 15
0
Lærer
Forside

What is a list?

Trykk for å vende
Bakside

A collection of ordered items. Lists can hold different data types.

Trykk for å vende
Skjønner
Lærer fortsatt

Quiz(12 spørsmål)

Spørsmål 1 av 12

1. What is the main characteristic of an array?

Begreper i dette studiesettet(15)

What is a list?

A collection of ordered items. Lists can hold different data types.

What is an array?

A collection of items of the same data type stored in contiguous memory.

Difference between lists and arrays

Lists can hold varied data types; arrays are type-specific.

True or false: Lists are mutable.

True, because you can change a list after it's created.

True or false: Arrays can resize dynamically.

False, because arrays have a fixed size once defined.

Fill in the blank: In Python, a list is created using ____.

square brackets: []

What is indexing in lists?

Accessing elements by their position, starting from 0.

Define a two-dimensional array.

An array containing arrays, representing a grid structure.

What method adds an item to a list in Python?

The append() method adds an item at the end of the list.

Example of an array declaration in Java.

int[] nums = {1, 2, 3};

What does slicing a list mean?

Extracting a part of the list using a range of indices.

True or false: Arrays can store different data types.

False, because all elements must be of the same type.

Which is faster: list or array?

Arrays are generally faster due to fixed sizes and type consistency.

What does 'length' return for an array?

The number of elements in the array.

How to access the first element of a list?

Use index 0 like: listName[0].

Spørsmål i dette studiesettet(12)

1. What is the main characteristic of an array?

A.Fixed size
B.Dynamic size
C.Heterogeneous types
D.Unordered

2. Which of the following is NOT a property of a list?

A.Ordered
B.Heterogeneous
C.Fixed size
D.Mutable

3. How do you add an element to an array?

A.Append
B.Push
C.Update
D.Not possible

4. Which data structure is more memory efficient?

A.List
B.Array
C.Both
D.Depends on the data

5. In Python, how do you access the second item in a list?

A.list[1]
B.list[2]
C.list.first()
D.list.get(1)

6. Which is typically faster for accessing elements?

A.Lists
B.Arrays
C.Both are equal
D.Depends on language

7. What is the result of slicing a list?

A.An error
B.A single element
C.A new list
D.The original list

8. Which structure can contain different data types?

A.List
B.Array
C.Both
D.Neither

9. Which method removes the last item from a list?

A.pop()
B.remove()
C.delete()
D.discard()

10. What does an index out of range error indicate?

A.Correct access
B.Invalid index
C.Exceeds array size
D.Both B and C

11. Which programming language uses lists as a fundamental data type?

A.Java
B.C
C.Python
D.Assembly

12. Which operation would generally be slower on a list?

A.Appending
B.Inserting at start
C.Accessing last element
D.Removing last element

Relaterte studiesett

Lag ditt eget studiesett

Last opp en PDF, lim inn notatene dine, eller beskriv et tema – AI genererer flashkort, quizer og mer på sekunder.