Thursday , September 19 2024

The following snippet: def func(a, b): return b ** a print(func(b=2, 2))

Questions BankCategory: Python Essentials 1The following snippet: def func(a, b): return b ** a print(func(b=2, 2))
The following snippet:

def func(a, b):
    return b ** a
 
 
print(func(b=2, 2))
  • will output 2
  • is erroneous
  • will output 4
  • will output None

Explanation: The program will raise the SyntaxError, because the positional argument in the function call (2) follows the keyword argument (b=2). Changing the order of the arguments in the func() function invocation (i.e. func(2, b=2)) fixes the issue, in which case the program would output 4 as the result.

More Questions: Python Essentials 1 (PE1) Course Final Test