Create a flash card for every exception in Python with an explanation of each.

(75 cards)

1
Q

What is the base class for all exceptions in Python?

A

BaseException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: The Exception class is a subclass of BaseException.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What exception is raised when an invalid operation is performed on a data type?

A

TypeError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: The _______ exception is raised when an index is not found in a list.

A

IndexError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What exception is raised when a variable is referenced before it has been assigned?

A

UnboundLocalError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What type of error does a ValueError represent?

A

It represents an operation or function receiving an argument that has the right type but an inappropriate value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What exception is raised when trying to access a key that does not exist in a dictionary?

A

KeyError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: A ZeroDivisionError occurs when dividing by zero.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What exception is thrown for operations that exceed the limits of a data type?

A

OverflowError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Fill in the blank: The _______ exception is used to indicate that a function is not implemented.

A

NotImplementedError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What exception is raised when a file operation fails?

A

IOError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What exception is raised when an import statement fails to find the module?

A

ImportError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False: The AssertionError is raised when an assert statement fails.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What exception occurs when an attempt is made to access an attribute that does not exist?

A

AttributeError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What exception is raised when a floating point operation results in a value that cannot be represented?

A

FloatingPointError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fill in the blank: The _______ exception is raised when an operation is attempted on a closed socket.

A

socket.error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What exception is raised when a function receives an invalid argument?

A

TypeError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What exception is raised when an operation on a string is attempted that is not allowed?

A

ValueError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

True or False: The NameError is raised when a local or global name is not found.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What exception is raised when a method is called on an object of an inappropriate type?

A

AttributeError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Fill in the blank: The _______ exception is raised when a numerical calculation exceeds the maximum limit for a numeric type.

A

OverflowError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What exception is raised for an invalid operation in a generator?

A

StopIteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What exception is raised when there is an issue with the underlying operating system?

A

OSError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

True or False: The RuntimeError is raised when an error is detected that doesn’t fall under any other category.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the exception raised when a reference to a non-existent object is made?
ReferenceError
26
Fill in the blank: The _______ exception is raised when there is a problem with the Python interpreter.
SystemError
27
What exception is raised when trying to modify a tuple?
TypeError
28
What exception indicates that a string operation failed?
UnicodeError
29
True or False: The MemoryError is raised when an operation runs out of memory.
True
30
What exception is raised when an operation is performed on a data structure that has been modified?
RuntimeError
31
Fill in the blank: The _______ exception is raised when a function is not defined in the scope.
NameError
32
What exception is thrown when a user-defined exception is raised?
Exception
33
What exception is raised when an operation cannot be performed due to lack of resources?
ResourceWarning
34
True or False: The EOFError is raised when the end of a file is reached unexpectedly.
True
35
What exception is raised when a loop is executed too many times?
RecursionError
36
Fill in the blank: The _______ exception is raised when an assertion fails.
AssertionError
37
What exception indicates that a function's return was not handled correctly?
ValueError
38
True or False: The IndentationError is raised for incorrect indentation.
True
39
What exception is raised when a method is called with incorrect arguments?
TypeError
40
Fill in the blank: The _______ exception is raised when a method is called on an object that is not iterable.
TypeError
41
What exception is raised when an operation is attempted on a closed file?
ValueError
42
What exception is raised when an invalid value is encountered in a method?
ValueError
43
True or False: The KeyError is raised when attempting to access a non-existent key in a dictionary.
True
44
What exception is raised when an operation is attempted on an unsupported data type?
TypeError
45
Fill in the blank: The _______ exception is raised when a function is called with too few arguments.
TypeError
46
What exception is raised when a network operation fails?
OSError
47
What exception is raised when a function is called on an object that has been deleted?
ReferenceError
48
True or False: The SyntaxError is raised for incorrect syntax in Python code.
True
49
What exception is raised when a required resource is not available?
ResourceWarning
50
Fill in the blank: The _______ exception is raised when a method is called that cannot be executed.
NotImplementedError
51
What exception is raised when an invalid operation is attempted on a file?
IOError
52
What exception occurs when a division by zero is attempted?
ZeroDivisionError
53
True or False: The TypeError is raised when an operation is performed on incompatible types.
True
54
What exception is raised when there are too many levels of recursion?
RecursionError
55
Fill in the blank: The _______ exception is raised when a requested operation cannot be performed.
RuntimeError
56
What exception is raised when a list index is out of range?
IndexError
57
What exception is raised when an invalid key is accessed in a dictionary?
KeyError
58
True or False: The IndentationError is a subclass of SyntaxError.
True
59
What exception is raised when a string operation fails due to encoding/decoding issues?
UnicodeError
60
Fill in the blank: The _______ exception is raised when an invalid argument is passed to a built-in function.
ValueError
61
What exception is raised when an attempt is made to access a non-existent attribute of an object?
AttributeError
62
True or False: The ImportError is raised when a module cannot be found or imported.
True
63
What exception is raised when a variable is referenced before assignment?
UnboundLocalError
64
Fill in the blank: The _______ exception is raised when an operation is attempted on an object that is not callable.
TypeError
65
What exception is raised when a file operation fails due to an I/O error?
IOError
66
What exception is raised when an invalid operation is performed on a string?
ValueError
67
True or False: The MemoryError is raised when there is insufficient memory to continue.
True
68
What exception is raised when an operation cannot be completed due to lack of memory?
MemoryError
69
Fill in the blank: The _______ exception is raised when an invalid index is accessed in a sequence.
IndexError
70
What exception is raised when the length of a list exceeds its maximum size?
OverflowError
71
What exception is raised when an operation is performed on a closed file?
ValueError
72
True or False: The RuntimeError is raised for errors that do not fall into any specific category.
True
73
What exception is raised when a user-defined exception is thrown?
Exception
74
Fill in the blank: The _______ exception is raised when there is a failure in the interpreter.
SystemError
75
What exception is raised when a method is called on an object that cannot be modified?
TypeError