The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Generate Python flashcards

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:

python
def function_name(parameters): # function body return result

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:

python
import module_name

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:

python
[expression for item in iterable if condition]

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:

python
try: # risky code except ExceptionType: # handle error

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:

python
with open('filename.txt', 'r') as file: content = file.read()

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:

python
for item in my_list: print(item)

Flashcard 13
Q: How do you define a class in Python?
A:

python
class ClassName: def __init__(self, param): self.param = param

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:

python
if key in my_dict: # do something

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?

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About