Thursday , September 19 2024

The following snippet: def function_1(a): return None def function_2(a): return function_1(a) * function_1(a) print(function_2(2))

Questions BankCategory: Python Essentials 1The following snippet: def function_1(a): return None def function_2(a): return function_1(a) * function_1(a) print(function_2(2))
The following snippet:

def function_1(a):
    return None
 
 
def function_2(a):
    return function_1(a) * function_1(a)
 
 
print(function_2(2))
  • will output 4
  • will cause a runtime error
  • will output 16
  • will output 2

Explanation: The None object has no arithmetic operators defined – the program will raise the TypeError exception, because the NoneType type cannot be the * operator’s operand.

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