.py
like add.py . Now use the import statement to import the saved file as follows.
[c]import add
addition.add(100,200)
addition.add(300,400) [/c]
Now compile the code result will be as follows.
[c]>>>
300
700
>>> [/c]
The following is an example to access multiple modules at a time.
message.py
[c]def msg_method():
print "Welcome"
return [/c]
display.py
[c]def display_method():
print "Welcome to splessons"
return [/c]
original.py
[c]import message,display
msg.msg_method()
display.display_method() [/c]
Now compile the code result will be as follows.
[c]>>>
Welcome
Welcome to splessons
>>> [/c]
from? import *
one can easily import whole module. The following is the syntax.
[c]from <module_name> import *
</module_name> [/c]
The following is an example.
area.py
[c]def circle(r):
print 3.14*r*r
return
def square(l):
print l*l
return
def rectangle(l,b):
print l*b
return
def triangle(b,h):
print 0.5*b*h
return [/c]
area1.py
[c]from area import *
square(10)
rectangle(2,5)
circle(5)
triangle(10,20) [/c]
Now compile the code result will be as follows.
[c]>>>
100
10
78.5
100.0
>>> [/c]
tan(n)
.