Paper 4 General TIPS

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 38

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

39 Terms

1
What function is used to open a file in Python?
open(filename, mode)
New cards
2
What mode should you use to read a file?
'r' (read mode)
New cards
3
What mode should you use to write to a file?
'w' (write mode, overwrites existing content)
New cards
4
What mode should you use to append to a file?
'a' (append mode, adds to existing content)
New cards
5
How do you read all lines from a file at once?
file.readlines()
New cards
6
How do you write a list of strings to a file?
file.writelines(list_of_strings)
New cards
7
How do you initialize an empty list in Python?
my_list = []
New cards
8
How do you declare a 2D array in Python?
my_array = [[0] * cols for _ in range(rows)]
New cards
9
How do you append an item to a list?
my_list.append(item)
New cards
10
How do you insert an element at a specific position in a list?
my_list.insert(index, item)
New cards
11
How do you remove an element from a list?
my_list.remove(item) or my_list.pop(index)
New cards
12
What is a linked list?
A data structure where elements (nodes) are connected using pointers.
New cards
13
How do you define a node in a linked list in Python?
class Node: def __init__(self, data): self.data = data; self.next = None
New cards
14
What is a head node in a linked list?
The first node of the linked list.
New cards
15
What does a linked list node store?
A data value and a pointer to the next node.
New cards
16
What value is used to indicate the last node in a linked list?
-1 or None (depends on implementation).
New cards
17
How do you define a class in Python?
class ClassName: followed by a constructor.
New cards
18
What is a constructor method in Python?
__init__(self, parameters) initializes an object.
New cards
19
What is encapsulation?
Restricting direct access to object attributes (use private variables).
New cards
20
How do you define a private attribute in Python?
Prefix it with self.__attribute_name.
New cards
21
What is a getter method?
A method that returns the value of a private attribute.
New cards
22
What is a circular queue?
A queue where the last position connects to the first.
New cards
23
How do you check if a circular queue is full?
If (Tail + 1) % size == Head.
New cards
24
How do you add an item to a circular queue?
Using an enqueue() function.
New cards
25
How do you remove an item from a circular queue?
Using a dequeue() function.
New cards
26
What is a function in Python?
A reusable block of code that performs a task.
New cards
27
How do you define a function in Python?
def function_name(parameters):
New cards
28
What does the return keyword do?
It sends back a value from a function.
New cards
29
What is the difference between return and print?
return gives a value back, print just displays it.
New cards
30
How do you pass parameters by reference in Python?
Mutable objects (lists, dicts) are passed by reference automatically.
New cards
31
What sorting algorithm is best for small lists?
Insertion Sort or Bubble Sort.
New cards
32
What is the time complexity of QuickSort?
O(n log n) on average.
New cards
33
How does Binary Search work?
It divides the sorted array in half and searches recursively.
New cards
34
What is the worst-case time complexity of Linear Search?
O(n)
New cards
35
What is the advantage of Merge Sort?
It's stable and works well for large datasets.
New cards
36
How do you handle errors in Python?
Using try-except blocks.
New cards
37
What does the except block do?
Catches and handles exceptions.
New cards
38
What exception is raised for division by zero?
ZeroDivisionError
New cards
39
What exception is raised for accessing a non-existent list index?
IndexError
New cards

Explore top notes

note Note
studied byStudied by 14 people
1005 days ago
4.0(1)
note Note
studied byStudied by 162 people
624 days ago
5.0(1)
note Note
studied byStudied by 16 people
122 days ago
5.0(1)
note Note
studied byStudied by 22 people
743 days ago
5.0(1)
note Note
studied byStudied by 61 people
882 days ago
4.0(1)
note Note
studied byStudied by 8 people
176 days ago
5.0(1)
note Note
studied byStudied by 10 people
898 days ago
5.0(1)
note Note
studied byStudied by 255 people
686 days ago
4.8(9)

Explore top flashcards

flashcards Flashcard (127)
studied byStudied by 31 people
911 days ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 19 people
266 days ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 8 people
784 days ago
5.0(1)
flashcards Flashcard (28)
studied byStudied by 29 people
737 days ago
5.0(2)
flashcards Flashcard (67)
studied byStudied by 9 people
837 days ago
5.0(1)
flashcards Flashcard (315)
studied byStudied by 51 people
763 days ago
5.0(4)
flashcards Flashcard (29)
studied byStudied by 15 people
379 days ago
5.0(1)
flashcards Flashcard (26)
studied byStudied by 84 people
17 days ago
5.0(1)
robot