+ 2
Can someone tell me what actually modules are,how do you use and make them ?
How do modules work .
14 Réponses
+ 2
As I can see your first half of the question is solved...
.
Now how to make your own modules?
.
Make a file named somemodule.py
---------------
# this is somemodule.py
def greet(name):
print "Hello "+name+"!!"
---------------
Another file called whatever.py
---------------
#this is where you want to import the #previously created module
import somemodule
name=input('Enter your name : ")
greet(name)
--------------
+ 2
Ivan..
Check my previous comment...
In *whatever.py* section
It shows how to import..
.
What are modules?
- A package or bundle of functions and defined variables by a programmer, such that we don't have to write it all again.. Instead a simple import and call would do the job..
.
Now, why to import modules?
-Answer is simple.. To use functions and variables from those modules/bundles...
+ 1
Modules - the result of the work of other programmers that you can use in your code. For example, to do heavy mathematical calculations, you will need to connect the math module.
+ 1
hi I am Aakash .......
from India ....
actually module is a function to call needed resources from library..
like to call pi from maths...
call squateroot from math calling sort....
calling random from library to make a series of random numbers chosen by computer itself...
etc ....
I hope you understand ....
+ 1
To Aakash: thanks VERY much!! But can you make modules?
+ 1
Thanks VERY much Shahi!!! everyone please leave a mark up for him ,now I'm left with only three questions here they are :
what is importing modules?,
How to import modules? and
Why import modules?
+ 1
To:shahi
Still don't get it
+ 1
You know C ?
We import/include "math.h" for functions like sqrt,sin,cos,tan,log,etc and some constants like PI,e,etc
- stdio.h for printf, scanf, etc
.
Similarly here we use import module
+ 1
I don't know C
+ 1
Ok..
.
Suppose u need to sort an array..
And u dont know any sorting program logic..
So I'll make a module/bundle having that function within..And pass a copy to u..
.
So u'll need to use "import mybundle.py"
Then, u'll be able to use sorting function within mybundle and complete your task..
+ 1
To:Shahi
THANK YOU VERY MUCH I get it.
0
Hello Ivan. I'm Ilya
0
Hello Ilya I'm Ivan
0
If you are Russian, let's move on Russian language.