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.
Built-in namespaces
Global namespaces
- 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.
Very clear explanation ..Thank u 😍😊
ReplyDeleteWelcome..
Delete