LIVE Course for free

Rated by 1 million+ students
Get app now
JEE MAIN 2023
JEE MAIN 2023 TEST SERIES
NEET 2023 TEST SERIES
NEET 2023
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
41 views
in Python by (3.0k points)
What is the difference between a local variable and a global variable in Python?

Please log in or register to answer this question.

1 Answer

0 votes
by (3.0k points)
A local variable in Python is a variable that is defined within a function or block of code. It can only be accessed within that function or block of code, and once the function or block is exited, the local variable is destroyed.

A global variable in Python is a variable that is defined outside of any function or block of code. It can be accessed from anywhere within the code, including within functions.

The main difference between local and global variables is that local variables are only accessible within the function or block of code where they are defined, while global variables can be accessed from anywhere in the code.

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...