Here are Python flashcards covering core concepts, syntax, and useful built-in functions:
Flashcard 1
Q: What is the correct way to define a function in Python?
A:
Flashcard 2
Q: What is the output of print(type([1, 2, 3]))?
A: <class 'list'>
Flashcard 3
Q: How do you import a module in Python?
A:
Flashcard 4
Q: What does len() do in Python?
A: Returns the number of items in an object (like a list, string, tuple, etc.)
Flashcard 5
Q: How do you write a list comprehension in Python?
A:
Flashcard 6
Q: What is the difference between is and == in Python?
A: is checks for identity (same memory location); == checks for equality in value.
Flashcard 7
Q: How do you handle exceptions in Python?
A:
Flashcard 8
Q: What is a lambda function?
A: An anonymous function defined with the lambda keyword.
Example: lambda x: x + 1
Flashcard 9
Q: How do you read a file in Python?
A:
Flashcard 10
Q: What are Python’s built-in data types?
A: int, float, str, list, tuple, dict, set, bool
Flashcard 11
Q: What is a dictionary in Python?
A: A collection of key-value pairs defined using {}.
Example: {"name": "Alice", "age": 30}
Flashcard 12
Q: How do you iterate over a list in Python?
A:
Flashcard 13
Q: How do you define a class in Python?
A:
Flashcard 14
Q: What is the purpose of __init__ method?
A: It initializes a newly created object; it’s the constructor in Python.
Flashcard 15
Q: What is slicing in Python?
A: Accessing a subset of a sequence using start:stop:step notation.
Example: my_list[1:5:2]
Flashcard 16
Q: How do you check if a key exists in a dictionary?
A:
Flashcard 17
Q: What is a set in Python?
A: An unordered collection of unique elements.
Example: {1, 2, 3}
Flashcard 18
Q: How do you install external packages in Python?
A: pip install package_name
Flashcard 19
Q: What does the map() function do?
A: Applies a function to all items in an iterable.
Example: map(lambda x: x*2, [1, 2, 3])
Flashcard 20
Q: What does the filter() function do?
A: Filters elements of an iterable based on a function returning True or False.
Would you like more cards focused on advanced topics like decorators, generators, or libraries like NumPy and pandas?