Flashcards
A question on one side, the answer on the other. Cards you know come back less often, and those you don't come back today.
Review
Leitner boxes: after “I know it” a card returns in 1, 3, 7, 14 days, after “Not yet” it goes straight back to the first box.
All cards
Python
What does len(x) return?
The number of items in a sequence or collection: characters in a string, items in a list, keys in a dict.
How does a tuple differ from a list?
A tuple (1, 2) is immutable, while a list [1, 2] can be changed. That is why a tuple can be a dict key.
What is an f-string?
A string with an f prefix whose braced expressions are evaluated in place: f'Hello, {name}'.
What does d.get('k') do if the key is missing?
It returns None (or the second argument if given) and raises no KeyError, unlike d['k'].
What does [x * x for x in range(4)] return?
The list [0, 1, 4, 9]: a list comprehension that builds squares of the numbers 0..3.
What is the danger in def f(a=[])?
The default is created once when the function is defined, so the mutable list is shared across all calls. Use a=None instead.
How does is differ from ==?
== compares values, while is checks whether both names refer to the same object in memory.
What does yield do inside a function?
It turns the function into a generator: values are produced one at a time, pausing between next() calls without building a full list.
What is the with statement for?
It manages a context: it guarantees a resource such as a file is closed even if an error occurs inside.
What do *args and **kwargs mean?
*args collects extra positional arguments into a tuple, and **kwargs collects keyword arguments into a dict.
JavaScript
How does let differ from const?
A let variable can be reassigned, while const forbids reassignment. Both are block scoped.
How does === differ from ==?
=== compares without type coercion, while == coerces first: 0 == '0' is true, but 0 === '0' is false.
What does arr.push(x) do?
It appends an item to the end of the array, mutates the array and returns its new length.
What does typeof null return?
The string 'object'. This is a long-standing quirk of the language kept for compatibility.
What does arr.map(fn) do?
It returns a new array of the same length with the result of fn for each item, leaving the original untouched.
What is a closure?
A function that remembers variables from its outer scope even after the outer function has returned.
How do arrow functions differ regarding this?
It has no own this and takes it from the surrounding scope where it was created.
What does await do?
It pauses an async function until a promise settles and returns its value (or throws if the promise is rejected).
Why is NaN === NaN false?
By specification NaN is not equal even to itself. Use Number.isNaN(x) to test for it.
Which runs first: setTimeout(f, 0) or Promise.then(g)?
g runs first: promise microtasks run before the next timer macrotask.
Git
What does git init do?
It creates a new repository in the current folder: a hidden .git directory holding the history.
How does git add differ from git commit?
git add puts changes into the index (staging area), and git commit records the staged changes as a snapshot in history.
What does git status show?
The current branch, staged changes, unstaged changes and untracked files.
What does git clone URL do?
It copies a remote repository with its whole history into a new local folder and sets up origin.
What does git stash do?
It shelves uncommitted changes on a separate stack and restores a clean working tree. Bring them back with git stash pop.
How does git merge differ from git rebase?
merge joins branches with a merge commit. rebase replays a branch's commits on top of another, rewriting history into a line.
What does git reset --hard HEAD~1 do?
It moves the branch back one commit and discards the index and working files to match, which is destructive.
How does git revert differ from git reset?
revert creates a new commit that undoes a given commit without rewriting history, so it is safe on shared branches.
What does git cherry-pick <hash> do?
It applies the changes of one chosen commit as a new commit on the current branch.
How does git fetch differ from git pull?
fetch only downloads new data from the remote, while pull also integrates it into the current branch (fetch + merge).
Command line
What does pwd do?
It prints the full path of the current working directory.
What does ls -la show?
A long listing of all files, including hidden ones (starting with a dot): permissions, owner, size, date.
What does cd - do?
It switches back to the previous working directory.
What does chmod +x script.sh do?
It adds the execute permission to the file, so it can be run as ./script.sh.
What does the | symbol do on the command line?
A pipe: it feeds the standard output of the left command into the standard input of the right one, e.g. ls | wc -l.
How does > differ from >>?
> overwrites the file with the command's output, while >> appends to its end.
What does $? hold?
The exit status of the last command: 0 means success, any other number means failure.
Why quote a variable as "$var"?
Without quotes a value containing spaces is split into several words and subject to globbing. Quotes keep it intact.
What does command 2>&1 do?
It redirects the error stream (descriptor 2) to wherever standard output (descriptor 1) goes.
What does set -e do at the top of a script?
It aborts the script as soon as a simple command returns a non-zero status. Often combined with -u and -o pipefail.
SQL
What does SELECT * FROM users do?
It returns all columns and all rows of the users table.
What is WHERE for?
It filters rows by a condition before grouping and output: WHERE age >= 18.
What does ORDER BY price DESC do?
It sorts the result by price in descending order, from largest to smallest.
What is a PRIMARY KEY?
A column (or set of columns) that uniquely identifies a row: values are unique and cannot be NULL.
How does INNER JOIN differ from LEFT JOIN?
INNER JOIN keeps only rows matching in both tables, while LEFT JOIN keeps all left rows and fills NULL where there is no match.
How does WHERE differ from HAVING?
WHERE filters individual rows before grouping, while HAVING filters groups after GROUP BY and can use aggregates.
Why does x = NULL not work as a check?
Any comparison with NULL yields unknown, not true. Write x IS NULL or x IS NOT NULL instead.
Why create an index?
To speed up lookups and sorting on a column. The cost is more storage and slower inserts and updates.
What does a transaction (ACID) guarantee?
Atomicity, consistency, isolation and durability: a group of operations is applied completely or not at all.
How does UNION differ from UNION ALL?
UNION merges results and removes duplicates, while UNION ALL keeps every row and is therefore faster.
HTML
What is <!doctype html> for?
It tells the browser this is modern HTML5 and enables standards mode instead of quirks mode.
Which tag creates a link?
The <a> tag with an href attribute: <a href="https://example.com">text</a>.
What is the alt attribute on <img> for?
It is a text description of the image: screen readers read it and browsers show it if the image fails to load.
How does <ul> differ from <ol>?
<ul> is an unordered (bulleted) list and <ol> is an ordered (numbered) one. Items in both go in <li>.
What are semantic tags?
Tags that convey a block's meaning, such as <header>, <nav>, <main>, <article>, <footer>. They help accessibility and SEO.
How do you associate a <label> with an input?
With a for attribute equal to the input's id, or by nesting the input inside the <label>. Clicking the label then focuses the field.
What is <meta name="viewport" ...> for?
It sets width and scale on mobile devices: width=device-width, initial-scale=1. Without it the page renders as on a wide desktop viewport.
How do block elements differ from inline ones?
Block elements (<div>, <p>) start on a new line and fill the width; inline ones (<span>, <a>) flow within text and size to their content.
How does defer differ from async on <script>?
Both fetch the script without blocking parsing. defer runs after HTML parsing in document order, async runs as soon as it is loaded, in any order.
What are data-* attributes?
Custom attributes for storing data on an element, e.g. data-id="5". In JS they are available as element.dataset.id.
CSS
How do you select elements by class in CSS?
With a dot before the class name: .card { color: red; } applies to all elements with class="card".
What does the box model consist of?
From inside out: content, padding, border and margin.
How does margin differ from padding?
padding is the space between the content and the border inside the element, while margin is the space outside the border, between neighbours.
What does display: flex do?
It makes the element a flex container: children line up in a row or column, aligned with justify-content and align-items.
How does the browser choose between conflicting rules?
By selector specificity (id beats class beats tag), and on a tie the later rule wins. !important overrides that.
How does position: absolute work?
The element is taken out of the flow and positioned relative to the nearest ancestor whose position is not static.
What does box-sizing: border-box change?
width and height then include padding and border, so the element does not grow when padding is added.
How does rem differ from em?
rem is relative to the root html font size, while em is relative to the current element's font size (the parent's for font-size itself).
What is @media for?
It applies styles only when a condition holds, such as viewport width: @media (max-width: 600px) { ... }. It underpins responsive layout.
What does 1fr mean in CSS Grid?
One share of the container's free space: grid-template-columns: 1fr 2fr splits the width 1 to 2.
Go
What does the := operator do?
It declares a variable with a type inferred from the expression: x := 5. It works only inside functions.
Where does a Go program start executing?
From the main function in package main: package main and func main() { ... }.
Can a Go function return multiple values?
Yes: func div(a, b int) (int, error). This is the usual way to return a result together with an error.
What is the zero value of Go variables?
An uninitialized variable gets its type's zero value: 0 for numbers, "" for strings, false for bool, nil for pointers, slices and maps.
How does a slice differ from an array?
An array [3]int has a fixed length that is part of its type, while a slice []int is a dynamic window over an array with a length and capacity.
What does go f() do?
It runs f in a new goroutine, a lightweight thread managed by the Go scheduler. The call does not wait for it to finish.
How does an unbuffered channel work?
For ch := make(chan int) a send ch <- v blocks until another goroutine receives with <-ch, and vice versa.
When does defer run?
A deferred call runs just before the function returns; multiple defers run in reverse (LIFO) order. Typical use: defer f.Close().
How does a type implement an interface in Go?
Implicitly: having all of the interface's methods is enough. There is no implements keyword.
What happens when you write to a nil map?
The program panics. Reading from a nil map is safe and gives the zero value, but you can write only after make(map[K]V).
C++
How do you print text in C++?
Through the std::cout stream from <iostream>: std::cout << "Hi" << std::endl;.
What does #include <iostream> do?
The preprocessor pastes the header's declarations of I/O streams such as std::cin and std::cout into the file.
What is int main()?
The program entry point. The returned value goes to the OS as the exit code (0 means success), and return 0 may be omitted in main.
What is a reference int& r = x;?
Another name for the variable x: changing r changes x. A reference must be initialized and cannot be rebound to another object.
Why delete after new?
new allocates heap memory and delete frees it. Without it you leak memory. Arrays pair new[] with delete[].
What does std::unique_ptr<T> give you?
A smart pointer with a single owner: it calls delete automatically at scope exit (RAII); it cannot be copied, only moved.
What is std::vector<T>?
A dynamic array with contiguous storage: fast index access and amortized O(1) push_back.
What does const mean in int get() const?
The method does not modify the object's state, so it can also be called on const objects.
What does the virtual keyword do on a method?
It enables dynamic dispatch: through a base-class pointer or reference the derived class's override is called.
Why does a base class need a virtual destructor?
So that delete through a base pointer correctly runs the derived destructor. Without it the behavior is undefined.
Fundamentals
What is a variable?
A named piece of memory that stores a value the program can read and change.
What is an algorithm?
A finite sequence of precise steps that solves a problem and finishes in finite time.
How does a compiler differ from an interpreter?
A compiler translates the whole program to machine code (or bytecode) before running, while an interpreter executes the code as it reads it.
What is an API?
An application programming interface: a defined set of functions or requests through which one program uses another's capabilities.
What is recursion?
An approach where a function calls itself on a smaller problem. It needs a base case, otherwise it recurses forever and overflows the stack.
How does a stack differ from a queue?
A stack works as LIFO (last in, first out), while a queue works as FIFO (first in, first out).
How does a hash table work?
A hash function maps a key to an array index, giving O(1) average access. Collisions are handled by chaining or open addressing.
What does Big-O notation describe?
How an algorithm's time (or memory) grows as input size n grows, ignoring constant factors: e.g. O(n) is linear, O(n^2) is quadratic.
What is HTTP and what does status 404 mean?
HTTP is the request-response protocol between client and server on the web. Status 404 means the requested resource was not found.
Why does binary search run in O(log n)?
It works only on sorted data and discards half of the range at each step by comparing the middle element with the target.
More in the Study
Knowledge sticks through repetition
The courses bring you back to what you've covered, and the daily streak helps you keep going.