Functions & Scope · Question 2 · Easy

The greet function below prints a message but has no return statement. What appears on the screen?

def greet(name):
    print("Hi", name)

result = greet("Asha")
print(result)
  1. Hi Asha None
  2. Hi Asha
  3. Hi Asha Hi Asha
  4. None
Answer and explanation

Answer: A. Hi Asha None

Explanation: Calling greet prints Hi Asha. A function that finishes without a return statement returns None, so result is None and the second print shows None.

Previous: A canteen bill function has two default parameters. What does this code print… · Next: In Python, what value does a function give back when its body ends without…

Practise functions & scope

Try a fresh set of functions & scope questions with an explanation after every answer, free and without signing up: Functions & Scope practice. Or sit a full placement mock test.

More functions & scope questions

More python practice

Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge