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
Answer and explanation
Concise answer
name
Why this is correct
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.
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
