Programming Part 6 Flashcards
(20 cards)
What is unit testing?
Testing individual pieces of code (like functions) in isolation.
What Python module is commonly used for testing?
unittest or pytest
What is an assertion?
A statement that checks if a condition is True; used in tests.
How do you write a basic test function in pytest?
Define a function with a test_ prefix and use assert statements.
Why is automated testing important?
It helps catch bugs early and ensures consistent behavior.
Why use Jupyter notebooks in data science?
To combine code, output, and narrative in a single, interactive document.
What is a code cell in Jupyter?
A block that can be executed independently to run code.
How do you restart the kernel in Jupyter?
Use the ‘Restart Kernel’ option to clear memory and re-run.
How can you ensure results are reproducible?
Set random seeds, document dependencies, and organize code.
What does it mean to ‘restart and run all’ in a notebook?
Clears all variables and executes every cell from top to bottom.
Why is version control important?
It tracks changes, supports collaboration, and enables rollback.
What is Git?
A distributed version control system for tracking changes in files.
What does ‘git commit’ do?
Saves a snapshot of tracked changes.
What does ‘git push’ do?
Sends local commits to a remote repository.
What does ‘git pull’ do?
Fetches changes from a remote repository and merges them.
What is a script in Python?
A file with code intended to be executed from top to bottom.
What is a function in the context of code reuse?
A reusable block of code that performs a specific task.
What is modular code?
Code that is broken into functions or files that each handle one responsibility.
Why is code documentation important?
It helps others (and your future self) understand what the code does.
What is the difference between a script and a notebook?
Scripts are linear and file-based; notebooks are interactive and cell-based.