First let us start with dictionary..
The dictionary is defined in the format: key:value
For example,
dict={'name' : 'Python', 'version' : 2.7, 'new version' : 3.5}
In the dictionary, name is associated to python, version is associated to 2.7 and so on.
Now we start with definition of MODULES..
Modules are like dictionaries, we can think module is a python file (*.py) and then it can be imported and used. The modules can contain some functions and variables.
For example, if i have a dictionary like this
mydict={'Job' : "Research"}
then its module can be created as
#this file need to be saved as mydict.py
def Job():
print("Research")
#let also define a variable
domain="Image Processing"
Now we can access the file (technically module need to be imported)
import mydict
mydict.Job()
print (mydict.domain)
Lets go to CLASSES now.. Class is an another construct to create a function group, data and pack them as a container.
class mydict(object):
def __init__(self):
self.domain="Image Processing"
def Job(self):
print("Research")
Like how we imported the modules, the class need to be instantiated and once don you get an OBJECT. The class can be instantiated as follows
my=mydict()
my. Job()
print (my.domain)
The python creates an object "my" which contains function and variables associated with the class mydict.
simple explanation of the init can be found here
https://micropyramid.com/blog/understand-self-and-__init__-method-in-python-class/
The dictionary is defined in the format: key:value
For example,
dict={'name' : 'Python', 'version' : 2.7, 'new version' : 3.5}
In the dictionary, name is associated to python, version is associated to 2.7 and so on.
Now we start with definition of MODULES..
Modules are like dictionaries, we can think module is a python file (*.py) and then it can be imported and used. The modules can contain some functions and variables.
For example, if i have a dictionary like this
mydict={'Job' : "Research"}
then its module can be created as
#this file need to be saved as mydict.py
def Job():
print("Research")
#let also define a variable
domain="Image Processing"
Now we can access the file (technically module need to be imported)
import mydict
mydict.Job()
print (mydict.domain)
Lets go to CLASSES now.. Class is an another construct to create a function group, data and pack them as a container.
class mydict(object):
def __init__(self):
self.domain="Image Processing"
def Job(self):
print("Research")
Like how we imported the modules, the class need to be instantiated and once don you get an OBJECT. The class can be instantiated as follows
my=mydict()
my. Job()
print (my.domain)
The python creates an object "my" which contains function and variables associated with the class mydict.
simple explanation of the init can be found here
https://micropyramid.com/blog/understand-self-and-__init__-method-in-python-class/
Comments
Post a Comment