Refer Global Variables inside a Function | Python Tutorials | Learn Python

Published: 21 June 2018
on channel: The Perfect Tutorials
33
5

Use Global Variables in Function easily!
-----------------------------------------------------------------------------------------------------------
Global Variables are something defined outside an entity which if needed to be referenced inside it, must be referenced using the "global" keyword.
-----------------------------------------------------------------------------------------------------------
Example:
------------------------------
testvar = 45;

def myfunction():
a = 10;
global testvar;
a = testvar + 10;
print(a);

myfunction();
------------------------------

Here if the "global" keyword is not used, it will throw an error as testvar is not a local variable of the function.

The output is 55.


Download the latest python release here: https://www.python.org/downloads/

Follow me on Instagram:   / the_perfect_tutorials  


On this page of the site you can watch the video online Refer Global Variables inside a Function | Python Tutorials | Learn Python with a duration of hours minute second in good quality, which was uploaded by the user The Perfect Tutorials 21 June 2018, share the link with friends and acquaintances, this video has already been watched 33 times on youtube and it was liked by 5 viewers. Enjoy your viewing!