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

1965 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Print "Hello World!" ten times without typing (or pasting) the print function more than once


Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


How do I define a function in Python?


What would you expect to be the output of the following code snippet: `a = [1, 2, 3]; b = a; b[1] = 4; print(a); print(b);`, and why?


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