Common Python Errors and Programming Concepts Flashcards

(31 cards)

1
Q

What is a syntax error?

A

A mistake in the structure of the code (e.g., missing colon or parentheses).

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

What is a runtime error?

A

An error that occurs while the program is running (e.g., division by zero).

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

What is a logical error?

A

A mistake in the program’s logic that causes incorrect results but no crash.

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

How do you convert a string to an integer?

A

Use int(“5”).

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

What is the order of operations in Python?

A

Parentheses, Exponents, Multiplication/Division, Addition/Subtraction (PEMDAS).

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

Are strings mutable?

A

No, they are immutable.

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

Are lists mutable?

A

Yes, you can change, add, or remove elements.

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

How do you slice a list or string?

A

Use [start:end], where end is not included.

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

What are some string methods?

A

.lower(), .find()

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

What are some list methods?

A

.append(), .sort()

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

What does the and operator do?

A

Returns True only if both conditions are True.

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

What does the or operator do?

A

Returns True if at least one condition is True.

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

What does the not operator do?

A

Reverses the Boolean value.

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

What is the output of range(5)?

A

0, 1, 2, 3, 4

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

What is an infinite loop?

A

A loop that never ends due to a missing exit condition.

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

How do you iterate over a list element-wise?

A

for item in my_list:

17
Q

How do you iterate index-wise?

A

for i in range(len(my_list)):

18
Q

Why use functions?

A

To reuse code, reduce repetition, and improve readability.

19
Q

What is variable scope?

A

Where a variable can be accessed (local vs. global).

20
Q

What happens if a function returns without a return statement?

21
Q

How do you access a value by key in a dictionary?

22
Q

How do you loop through dictionary items?

A

for key, value in dict.items():

23
Q

What are some dictionary methods?

A

.get(), .update()

24
Q

How do you open a file for reading?

A

open(“file.txt”, “r”)

25
How do you write to a file?
open("file.txt", "w") and then use .write()
26
What is a try/except block?
Catches and handles errors without crashing the program.
27
What are common exception types?
ValueError, IndexError
28
What is __init__ in a class?
The constructor method, used to initialize objects.
29
What is self in a class?
The instance of the object being accessed.
30
How do you define a class?
Use class ClassName:
31
What is operator overloading?
Customizing behavior of operators like + with methods like __add__.