Beispiel #1
0
 def test1(self):
     self.assertEqual(add(2, 4), 6)
     self.assertEqual(add(0, 0), 0)
     self.assertEqual(add(2.3, 3.6), 5.9)
     self.assertEqual(add('hello', 'world'), 'helloworld')
     self.assertEqual(add(2.3, 4.3), 6.6)
     self.assertNotEqual(add(-2, -2), 0)
Beispiel #2
0
import math

math  # l'import crea una nuova variabile che si riferisce al modulo
print(math.pi)

from math import pi, sqrt

print(pi)  # è ora possibile accedere a pi senza usare math.pi

####################
import myModule

print(myModule.add(3, 5))
Beispiel #3
0
# 匯入 myModule.py
import myModule
print(myModule.add(1, 3))
print(myModule.subtract(1, 3))

# 另一種定義 module 的方式,匯入 myModule2 資料夾
import myModule2
print(myModule2.add(1, 3))
print(myModule2.subtract(1, 3))
Beispiel #4
0
import myModule
sum=myModule.add(6,7)
print(sum)
Beispiel #5
0
        _ = system('clear')


# now call function we defined above
clear()

#######################################################################
## The function above is to clean the console each time run the code ##
#######################################################################

# We can use modules obtained from three ways:
# 1. Modules written by us
# 2. Third party modules from internet
# 3. Modules from the python libraries

# 1. MODULES WRITTEN BY US:
import myModule
myModule.add(2, 3)

# 2. THIRD PARTY MODULES FROM INTERNET: (use pip to install)
# In this case we're using colorama. To provide color to text in console.
# Importing the modules Fore, Back, Style, init from the library colorama
from colorama import Fore, Back, Style, init
# init module send reset sequences to turn off color changes at the end of every print automatically if is True.
init(autoreset=True)
print(Fore.RED + 'some red text')

# 3. MODULES FROM THE PYTHON LIBRARIES:
from datetime import date, timedelta
print(date.today())
print(timedelta(minutes=70))  # Will return time in hours
Beispiel #6
0
import sys
sys.path.append(r"C:\Users\admin\Desktop\python人工智能班2\day11\代码\sub")

import myModule

print(myModule.__all__)
print(myModule.add(10, 20))
p = myModule.Person("John", 24)
print(p)
    第一类:内置模块,也叫做标准库。此类模块就是python解释器给你提供的,比如我们之前见过的time模块,os模块
    第二类:第三方模块,第三方库。一些python大神写的非常好用的模块,必须通过pip install 指令安装的模块
    第三类:自定义模块。我们自己在项目中定义的一些模块
"""

# import
#  同一个模块不会引入多次 已经优化
import myModule
import myModule
import myModule

# qzy
# 8
name = '123'
print(name)  # 123
print(myModule.name)  # qzy

# 为模块起名
import myModule as my

print(my.name)  # qzy

# from ... import ...
from myModule import add

print(add())  # 8

# 与import的区别
#   好处:使用起来方便了
#   坏处:容易与当前执行文件中的名字冲突
Beispiel #8
0
import myModule

print("Addition is", myModule.add(2, 3))
print("Subtraction is", myModule.sub(4, 2))
print("Division is", myModule.div(10, 2))
print("Multiplication is", myModule.mul(5, 5))
#Check the script myFunctions in the folder named myDirectory
from myDirectory import myFunctions
# import myDirectory.myFunctions #Another way of importing scripts
#import myDirectory.myFunctions as func #Another alternative
#from myDirectory import myFunctions as func #Alternative
import myModule
print("Add:", myModule.add(2, 3))
print("Multiplication:", myModule.Multipy(2, 3))

#Files from a different folder
print(myFunctions.Divide(6, 2))
print(myFunctions.Substraction(6, 2))