
Ultimate access to all questions.
A data engineer that is new to using Python needs to create a Python function to add two integers together and return the sum. Which of the following code blocks can the data engineer use to complete this task?
A
function add_integers(x, y):
return x + y
function add_integers(x, y):
return x + y
B
function add_integers(x, y):
x + y
function add_integers(x, y):
x + y
C
def add_integers(x, y):
print(x + y)
def add_integers(x, y):
print(x + y)
D
def add_integers(x, y):
return x + y
def add_integers(x, y):
return x + y
E
def add_integers(x, y):
x + Y
def add_integers(x, y):
x + Y
Explanation:
Option D is the correct answer because:
def keyword to define functions, not function keyword (which is used in other languages like JavaScript).return x + y to actually return the sum to the caller.y variable (not uppercase Y).Why other options are incorrect:
function keyword instead of def - this is not valid Python syntax.function keyword and lacks a return statement - the function would return None.print() instead of return - this prints to console but doesn't return the value to the caller.Y (should be lowercase y) and lacks a return statement.Key Python concepts:
def function_name(parameters):return statement sends a value back to the callery ≠ Y)print() outputs to console but doesn't return a value for further processing