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

1787 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Create a program that checks for syntactical errors in an email address.


Explain why creating a list of several instances of one element using something like my_list = [a] * 5 can result in strange behaviour


Given a list of N numbers, use a single list comprehension to produce a new list that only contains those values that are: (a) even numbers, and (b) from elements in the original list that had even indices .


Why would I use dictionaries instead of a list?


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:

© 2025 by IXL Learning