21 cards · Public · Shuffle

Stanford CS106A - Python Programming Methodology

Unlock core Python programming skills with this comprehensive flashcard deck, mirroring Stanford CS106A's foundational concepts. Ideal for beginners, master variables, control flow, functions, data structures, and algorithmic thinking for robust problem-solving.

Cards in this deck

(21 cards)

Preview terms and definitions before starting your study session.

#1
Term
How do you iterate through keys, values, and key-value pairs in a dictionary?
Definition
  • Keys: for key in my_dict: or my_dict.keys()
  • Values: for value in my_dict.values():
  • Key-value pairs: for key, value in my_dict.items():
#2
Term
What is a variable in Python?
Definition
A named storage location that holds a value. Variables are dynamically typed in Python, meaning their type can change during execution. Example: x = 10, name = "Alice".
#3
Term
List the four primary built-in data types in Python.
Definition
1. int: Integers (e.g., 5, -100)
2. float: Floating-point numbers (e.g., 3.14, -0.5)
3. str: Strings (sequences of characters, e.g., "hello")
4. bool: Booleans (either True or False)
#4
Term
Explain type conversion (casting) in Python with an example.
Definition
Type conversion is changing a value from one data type to another. Python provides built-in functions like int(), float(), str(), and bool().
Example:
python2 lines
num_str = "123"
num_int = int(num_str) # Converts string "123" to integer 123
#5
Term
Describe the basic structure of an if/elif/else statement.
Definition
Used for conditional execution. Code blocks are executed based on whether a condition evaluates to True.
python6 lines
if condition1:
    # code if condition1 is True
elif condition2:
    # code if condition1 is False and condition2 is True
else:
    # code if all conditions are False
#6
Term
How do you iterate a specific number of times using a for loop?
Definition
Use the range() function. range(n) generates numbers from 0 up to (but not including) .
Example:
python2 lines
for i in range(5):
    print(i) # Prints 0, 1, 2, 3, 4
#7
Term
When would you use a while loop instead of a for loop?
Definition
A while loop is used when the number of iterations is not known beforehand and depends on a condition remaining True. A for loop is typically used when iterating over a sequence or a known range.
Example:
python4 lines
count = 0
while count < 3:
    print(count)
    count += 1
#8
Term
Define a simple Python function that takes two numbers and returns their sum.
Definition
python4 lines
def add_numbers(a, b):
    return a + b

result = add_numbers(5, 3) # result will be 8
Showing 8 of 21 cards in this deck.
Study All Now