logo

Question detail

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?

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

MCQ

Type

practice

Style

Topic

Programming

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?.

  1. A.greeting
  2. B.greet
  3. C.name
  4. 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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.