How do you debug a python program? (AI) Flashcards

(11 cards)

1
Q

What is the primary goal of debugging in Python?

A

Identifying and resolving errors, ensuring program logic is sound

Debugging is essential for maintaining code quality and functionality.

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

Name a basic technique for debugging in Python that involves outputting information to the console.

A
  • Using print statements

Print statements help track the flow of execution and variable values.

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

What is the purpose of assert statements in Python debugging?

A

Check if a condition is met and halt execution if false

Assert statements are useful for validating assumptions in the code.

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

What module provides advanced options for detailed runtime information and variable tracking in Python?

A

logging

The logging module allows for configurable logging levels and output formats.

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

What is pdb in Python?

A

The Python Debugger

Pdb allows setting breakpoints, navigating through code, and inspecting variables interactively.

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

How can you launch pdb from the command line?

A

Run your script with python -m pdb my_script.py

This command initializes the debugger for the specified script.

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

What is one way to use pdb inside a script?

A

Import pdb and place pdb.set_trace() where you want the breakpoint

This allows for interactive debugging at specific points in the code.

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

What are some features of modern IDEs for debugging in Python?

A
  • Breakpoints
  • Variable Watch
  • Interactive Control

IDEs like PyCharm and VS Code provide comprehensive debugging tools for developers.

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

What is the purpose of unit testing in Python debugging?

A

Define and run tests to ensure individual parts of the codebase work as expected

Tools like unittest and pytest are commonly used for unit testing.

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

What tool can be used for code profiling in Python?

A

cProfile

cProfile helps identify performance bottlenecks in large programs.

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

True or false: Each debugging method in Python has its strengths and ideal use-cases.

A

TRUE

A skilled programmer is familiar with various techniques and knows when to use each.

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