What's the difference between a local and a global variable?

A global variable can be accessed from anywhere within the program whereas a local one can only be accessed from within the method it's declared in.

JH
Answered by James H. Python tutor

2024 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Write a short program to print all the even numbers 1 to 100


How would you write a while loop to print all even numbers from 1-10?


What is the difference between a for and a while loop?


[Exam style] Python is an interpreted language. Explain what this means and how interpreted languages differ from compiled languages.


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning