local and global variables in python

Опубликовано: 23 Октябрь 2024
на канале: Everything About Computers
108
5

In this tutorial we will learn about local and global variables when working with functions.
In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a value anywhere within the function’s body, it’s assumed to be a local unless explicitly declared as global.

local and global variables comes into picture when one starts working with functions.
Any variable used within the function will be local to that function. It's life will be to the point the function is active. Any variable in the main program will be considered as global.