Python - 014 : Local and Global variables in python #python #pythonprogramming #pythontutorial

preview_player
Показать описание
How to use a global variable in a Python function?

There are 2 types of variables in python namely Local variables and Global variables. Local variables mean the variables that are declared inside a function or inside a method whose impact or scope is only present inside that specific block and it doesn’t affect the program outside that block.

Global variables mean the variables that are declared outside any function or method and these variables have an impact or scope through the entire program.

We can also instantiate global variables inside a function by using a global keyword, if we want to declare global variables outside a function then we may not need to use a global keyword.

If a variable with the same name globally and locally then inside the function where the local variable is declared the local value is used and the global value is used elsewhere.
Рекомендации по теме
welcome to shbcf.ru