Ejemplo n.º 1
0
import mymath   #imported from mymath created by me inside the project file so that i can use it in the python files
                #<from mymath import *> Thus by using this we can import all the modules from mymath
print(mymath.sum(10,20))   #after we use above syntax to import all modules we can simply use <print(sum(10,20))> instead
print(mymath.diff(10,5))   #and here we can use <print(diff(10,20))>

#we can also modify the name of imported file by using syntax <import mymath as da> here da is of ur choice
#now instead of using mymath evrywhere we can use its modified name i.e. da
Ejemplo n.º 2
0
import mymath as ma

print(ma.sum(7, 8))

print(ma.diff(7, 8))
Ejemplo n.º 3
0
import mymath

print(mymath.PI)
print(mymath.sum(3, 4))
print(mymath.sub(3, 4))
Ejemplo n.º 4
0
import mymath

print(mymath.sum(2, 3))
print(mymath.diff(5, 1))
Ejemplo n.º 5
0
#      Namespace
# --------------------

'''
When we import a module the file we imported its name is called namespace. See the example below

'''

# --------------------
#      Import
# --------------------

## Import entire module
import mymath # mymath is a filename and namespace

print ( mymath.sum(10, 2) ) # using mymath namespace we can call its function
print ( mymath.subtract(10, 2) )


## Import specific functions
from mymath import subtract

print ( subtract(2, 1) )


## Import all functions
from mymath import *

print ( sum(2, 5) )
print ( subtract(29, 1) )
Ejemplo n.º 6
0
import mymath as ma # from mymath.py

print(ma.sum(10,5))
print(ma.diff(10,5))

'''
OR

from mymath import *
print(sum(10,5))
print(diff(10,5))
'''
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 16 15:43:48 2020

@author: spiridiv
"""

import mymath

#module could be omported as alias as well
#import mymath as ma

print(mymath.sum(5, 10))
print(mymath.diff(10, 9))

#Or if want to import all only some of the functions inside the modules
# from mymath import *
# OR
# from mymath import sum - to import sum only
Ejemplo n.º 8
0
import mymath

print(mymath.sum(10, 5))
print(mymath.diff(10, 5))

import mymath as ma

print(ma.sum(10, 5))
print(ma.diff(10, 5))

from mymath import *

print(sum(10, 5))
print(diff(10, 5))
Ejemplo n.º 9
0
import mymath

print(mymath.sum(10, 2))
print(mymath.subtract(10, 2))
Ejemplo n.º 10
0
# Krystal Kwan
# 8/27/2016
# make 2 functions

import myart
import mymath


print("7 + 5 = %i" % mymath.sum(7, 5))

print("red + blue = %s" % myart.mix("red", "blue"))
Ejemplo n.º 11
0
print("\n")
print("--- Вызов функции стороннего модуля ---")

import math
res = math.cos(0.7)
print("результат функции math.cos: ", res)


print("\n")
print("--- Вызов функции собственного  модуля ---")

# пример подключения собственного модуля mymath
# при импорте образуется пространство имен модуля mymath
import mymath
m = mymath.sum(1, 4)
print("Результат сложения (из собственного модуля): ", m)
print("Переменная из собственного модуля: PI =", mymath.PI)

print("\n")
print("--- Пример подключения и вызов опредленной функции ---")
# В случае если нехочется создавать новое пространство имен, то можно
# импортировать по правилу: 
from mymath import max3
# в этом случае будет доступна только указанная функция
# для её вызова не требуется использовать пространство имен (имя модуля)
# при необходимости импорта нескольких функциц они перечисляются 
# через зарятую
# Для получения всего содержимого используется (*), при этом может 
# появится конфликт с уже существующими функциями 
Ejemplo n.º 12
0
 def test_sum_one_and_one(self):
     result = mymath.sum(1,1)
     self.assertEqual(result,2)
Ejemplo n.º 13
0
from mymath import *
import mymath as ma
import mymath

print(mymath.sum(20, 10))
print(mymath.diff(20, 10))
print(mymath.mult(20, 10))
print(mymath.divi(20, 10))

# Creating a alias name to import so that no need to always type mymath while
# envoke mymath.function_name everytime.
print(ma.sum(20, 10))

# If we ever feel to exclude the module name, and just envoke the function by
# its name, then :
print(sum(10, 20))
Ejemplo n.º 14
0
import mymath


def hello():
    print("hello world")


hello()

s = mymath.sum(1, 2)
print(s)
Ejemplo n.º 15
0
import mymath

print(mymath.sum(7, 8))

print(mymath.diff(7, 8))
'''By Ankush Chavan'''