Wednesday, December 23, 2020

Namespaces in python.

Before going into namespaces, let me tell you first, what a function is.

Functions contain a part of the main program, that has to be run multiple times.

Instead of writing the same lines again and again, they are put inside a function. The function is called when ever required.

Without function: 

 

With function: 

 

def function_name():

            lines of code 

is the syntax for writing function.The logic inside function are written with indentation(white spaces in front).

Namespaces in python

In python, all data you give as input are objects. If you create a variable a=2, 

2 is an object of class int and a is the name assigned to 2.

Look into the video to get a better understanding. 


Scope of namespaces.

There are three types of namespaces in python.

  1. Built-in namespaces

  2. Global namespaces

  3. Local namespaces.

     

There are id() and print() which, by now you would be familiar with, are called built-in namespaces. 

Global namespaces are variables or method that you create outside the function (or) in the beginning of your program.

The scope of Local namespaces are confined to that particular function.

Here is the video with example for your better understanding.

 


 

2 comments:

Anaconda Installation

In this post we will discuss about Anaconda and its installation. Anaconda comes with number of applications(jupyter notebook included), dat...