The function greet is called with 'Alice' as the argument for name.
Step 2: Evaluate the print statement output
It prints "Hello, Alice!" exactly as formatted by the f-string.
Final Answer:
Hello, Alice! -> Option D
Quick Check:
Function prints Hello, Alice! [OK]
Hint: op_args passes list items as function arguments [OK]
Common Mistakes:
Thinking op_args passes the list as one argument
Confusing variable name with string 'name'
Assuming function is not called
4. Identify the error in this PythonOperator usage:
def add(x, y):
return x + y
PythonOperator(
task_id='add_task',
python_callable=add,
op_kwargs={'x': 5, 'z': 3},
dag=dag
)
medium
A. python_callable must be a string
B. The function add does not accept argument 'z'
C. task_id is missing
D. op_kwargs should be a list, not a dict
Solution
Step 1: Check function parameters
The function add expects only 'x' and 'y' as arguments.
Step 2: Analyze op_kwargs keys
op_kwargs passes 'x' and 'z', but 'z' is not a valid parameter for add, causing an error.
Final Answer:
The function add does not accept argument 'z' -> Option B
Quick Check:
Extra argument 'z' causes error [OK]
Hint: Function args must match op_kwargs keys exactly [OK]
Common Mistakes:
Passing wrong argument names in op_kwargs
Thinking op_kwargs can be a list
Confusing python_callable type
5. You want to create a PythonOperator task that calls a function process_data which requires a list of numbers and a flag. The function signature is def process_data(numbers, verbose=False):. How do you correctly pass the arguments to the operator?
hard
A. PythonOperator(task_id='proc', python_callable=process_data, op_kwargs={'numbers': [1,2,3], 'verbose': True}, dag=dag)
B. PythonOperator(task_id='proc', python_callable=process_data, op_args=[1,2,3, True], dag=dag)
C. PythonOperator(task_id='proc', python_callable=process_data, op_args=[1,2,3], op_kwargs={'verbose': True}, dag=dag)
D. PythonOperator(task_id='proc', python_callable=process_data, args=[[1,2,3], True], dag=dag)
Solution
Step 1: Understand function parameters
process_data expects 'numbers' (list) and optional 'verbose' keyword argument.
Step 2: Match argument passing style
Using op_kwargs with keys 'numbers' and 'verbose' correctly passes both arguments by name.
Step 3: Check other options
B passes four positional arguments causing TypeError. C passes three positional arguments (1,2,3) plus verbose=True, but function expects only two positional arguments causing TypeError. D uses invalid 'args' parameter.
Final Answer:
PythonOperator(task_id='proc', python_callable=process_data, op_kwargs={'numbers': [1,2,3], 'verbose': True}, dag=dag) -> Option A
Quick Check:
Use op_kwargs for named args [OK]
Hint: Use op_kwargs for named arguments, op_args for positional [OK]
Common Mistakes:
Passing too many positional arguments
Using wrong parameter names like args instead of op_args
Mixing positional and keyword args incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.