Prepare for the A Level Computer Science OCR Exam with engaging quizzes, detailed explanations, and effective study tips. Maximize your readiness and boost your confidence for exam day!

Practice this question and more.


What can a global variable in Python be declared with?

  1. Static keyword

  2. Global keyword

  3. Instance keyword

  4. Const keyword

The correct answer is: Global keyword

A global variable in Python can be declared using the global keyword. This keyword allows you to define a variable within a function or block of code that refers to a variable defined outside that function or block, specifically in the global scope. This means the variable can be accessed and modified throughout the entire program, which is particularly useful for sharing data across different functions. When the global keyword is used inside a function, it tells Python that you are referring to the globally scoped variable, rather than creating a new variable that is local to the function. This helps maintain a clear distinction between local and global variables, providing better control over how data is accessed and manipulated within your program. The other options refer to concepts or keywords that do not apply to the declaration of global variables in Python. Static is more commonly associated with statically typed languages, instance relates to object-oriented programming and the scope of variables within class instances, and const is not a keyword used in Python for defining constants or variables.