April 2017
Beginner to intermediate
312 pages
7h 23m
English
There are two types of variables in a Python program: local and global variables. Local variables are local to a function, that is, it is a variable declared within a function is accessible within that function. The example is as follows:
def add_function(): a = 3 b = 2 c = a + b print("The sum of a and b is ", c)
In this example, the variables a and b are local to the function add_function. Let's consider an example of a global variable:
a = 3 b = 2 def add_function(): c = a + b print("The sum of a and b is ", c) add_function()
In this case, the variables a and b are declared in the main body of the Python script. They are accessible across the entire program. Now, let's consider this example: ...
Read now
Unlock full access