Exam-style question
Try this first
In this Python code, which variable is global? name = "Ava" def greet(): greeting = "Hello" print(greeting) Which variable is defined outside the function and can therefore be accessed from a wider part of the program?.
- A.greeting
- B.greet
- C.name
- D.print
Model answer
What a good answer should say
- name
Explanation
Why this works
name is defined outside greet, so it is the global variable in this example. greeting is defined inside the function and is local to that function.
Common mistake
No common mistake is linked to this question yet.
