Coding Python Final Exam

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/81

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:07 AM on 6/24/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

82 Terms

1
New cards

What data structure is immutable?

Tuple

2
New cards

What data structure uses square brackets []?

List

3
New cards

What data structure uses parentheses ()?

Tuple

4
New cards

What data structure stores key-value pairs?

Dictionary

5
New cards

What does len() return?

The number of items in a list, tuple, string, or other collection

6
New cards

What does append() do?

Adds one item to the end of a list

7
New cards

What does extend() do?

Adds all items from another collection to a list

8
New cards

What does remove() do?

Removes a specified value from a list

9
New cards

What does sort() do?

Sorts a list in ascending order

10
New cards

What does reverse() do?

Reverses the order of items in a list

11
New cards

What is indexing?

Accessing elements by their position number

12
New cards

What is the first index in a list?

0

13
New cards

What does a negative index do?

Counts from the end of the list

14
New cards

What does list[-1] return?

The last item in the list

15
New cards

What is slicing?

Selecting a range of elements from a list or string

16
New cards

What does list[start:end] return?

Elements from start up to but not including end

17
New cards

What does range(len(my_list)) allow you to do?

Loop through list indexes

18
New cards

What does % mean in Python?

Modulus (remainder)

19
New cards

What does index % 2 0 check?

If an index or number is even

20
New cards

What does index % 2 1 check?

If an index or number is odd

21
New cards

What is a for loop used for?

Repeating code for each item in a collection

22
New cards

How do you loop through values in a list?

for item in my_list

23
New cards

How do you loop through indexes in a list?

for i in range(len(my_list))

24
New cards

What is a nested loop?

A loop inside another loop

25
New cards

What is a 2D list?

A list containing other lists

26
New cards

How do you access an element in a 2D list?

my_list[row][column]

27
New cards

What does my_list[1][2] mean?

Row 2, column 3

28
New cards

What does my_list[1:3] do?

Returns rows 2 through 3, not including row 4

29
New cards

How can you create a 2D list?

By appending lists into another list

30
New cards

What is a list comprehension?

A shortcut for creating lists

31
New cards

Example of a list comprehension

[i ยท 2 for i in range(6)]

32
New cards

What is packing?

Storing multiple values in a collection such as a list or tuple

33
New cards

What is unpacking?

Assigning multiple variables from a collection

34
New cards

Example of unpacking

a, b, c = [1, 2, 3]

35
New cards

What is a string?

A sequence of characters

36
New cards

What does split() do?

Converts a string into a list

37
New cards

Example of split()

"Hello World".split() returns ["Hello", "World"]

38
New cards

What does join() do?

Converts a list into a string

39
New cards

Example of join()

" ".join(["Hello","World"]) returns "Hello World"

40
New cards

What does "a".join(["b","n","n"]) return?

banan

41
New cards

What is a dictionary?

A collection of key-value pairs

42
New cards

How do you access a dictionary value?

dictionary[key]

43
New cards

What does a dictionary map?

Keys to values

44
New cards

How do you loop through a dictionary?

for key in dictionary

45
New cards

What does compare?

Values

46
New cards

What does is compare?

Object identity (same object in memory)

47
New cards

If two lists contain the same values, what does return?

True

48
New cards

If two separate lists contain the same values, what does is usually return?

False

49
New cards

What file mode is used for reading?

'r'

50
New cards

What file mode is used for writing and overwriting?

'w'

51
New cards

What file mode is used for appending?

'a'

52
New cards

What file mode is used to create a new file only?

'x'

53
New cards

What does read() do?

Reads the entire file as a single string

54
New cards

What does read(size) do?

Reads a specific number of characters

55
New cards

What does readline() do?

Reads one line from a file

56
New cards

What does readlines() do?

Reads all lines and returns a list of strings

57
New cards

What does write() do?

Writes content to a file

58
New cards

What does write() return?

The number of characters written

59
New cards

What does seek() do?

Moves the file pointer to a specified position

60
New cards

What does seek(0) do?

Moves the file pointer to the beginning of the file

61
New cards

What does a positive seek offset do?

Moves the file pointer forward

62
New cards

What does close() do?

Closes an open file

63
New cards

Why should files be closed?

To save resources and ensure changes are written properly

64
New cards

What happens when a file is opened in 'w' mode?

Existing contents are overwritten

65
New cards

What happens when a file is opened in 'a' mode?

New content is added to the end

66
New cards

What does readlines() return?

A list where each element is a line from the file

67
New cards

What type of value does len() return?

Integer

68
New cards

What does print(my_list[3][1:]) do in a 2D list?

Prints elements from index 1 to the end of row 4

69
New cards

What is the output type of split()?

List

70
New cards

What is the output type of join()?

String

71
New cards

What is the difference between append() and extend()?

append adds one item; extend adds multiple items

72
New cards

Can tuples be modified after creation?

No

73
New cards

Can lists be modified after creation?

Yes

74
New cards

Can dictionaries be modified after creation?

Yes

75
New cards

What are the three most tested file-reading methods?

read(), readline(), readlines()

76
New cards

What are the three most common list methods?

append(), extend(), remove()

77
New cards

What are the most common list-processing functions?

len(), sort(), reverse()

78
New cards

What is the most important thing to remember about tuples?

They are immutable

79
New cards

What is the most important thing to remember about dictionaries?

They map keys to values

80
New cards

What is the most important thing to remember about 2D lists?

Use [row][column] indexing

81
New cards

What is the most important thing to remember about file mode 'w'?

It overwrites existing contents

82
New cards

What is the most important thing to remember about file mode 'a'?

It appends to the end without deleting existing content