๐Ÿ“‚์›น ๊ฐœ๋ฐœ(Web)/๐ŸํŒŒ์ด์ฌ(Python)

ํŒŒ์ด์ฌ ๋ชจ๋“ˆ(module)

๐Ÿ‘ฉ‍๐ŸŽ“์ธํ…”๋ฆฌ๊ฐ์ž๐Ÿฅ” 2023. 2. 1. 17:00

๋ชจ๋“ˆ(module)
    ๋ณ€์ˆ˜๋‚˜ ํ•จ์ˆ˜ ๋˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋ชจ์•„ ๋†“์€ ํŒŒ์ผ์„ ๋ชจ๋“ˆ์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

**์‚ฌ์šฉํ•  conveter ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ๋‘”๋‹ค.

MILES = 0.621371
POUND = 0.00220462

def kilometer_to_miles(kilometer):
    return kilometer * MILES

def gram_to_pounds(gram):
    return gram * POUND

 

1. ๋ชจ๋“ˆ ์‚ฌ์šฉ๋ฒ•
import ๋ชจ๋“ˆ๋ช…

 

import convertermiles = converter.kilometer_to_miles(150)
print('150km = {}miles'.format(miles))


pounds = converter.gram_to_pounds(1000)
print('1000g={}pounds'.format(pounds))

 

2. ๋ชจ๋“ˆ ์‚ฌ์šฉ๋ฒ•2
from ๋ชจ๋“ˆ๋ช… import ํ•จ์ˆ˜
form ๋ชจ๋“ˆ๋ช… import ํ•จ์ˆ˜1, ํ•จ์ˆ˜2
from ๋ชจ๋“ˆ๋ช… import * #์ปจ๋ฒ„ํ„ฐ์— ์žˆ๋Š” ๋ชจ๋“  ํ•จ์ˆ˜ ์“ฐ๊ฒ ๋‹ค

from converter import kilometer_to_miles

miles = kilometer_to_miles(160)
print('150km={}miles'.format(miles))

 

from converter import *

miles = kilometer_to_miles(150)
print('150km={}miles'.format(miles))

pounds = gram_to_pounds(1000)
print('1000g={}pounds'.format(pounds))

 

3. ๋ณ„๋ช… ์‚ฌ์šฉํ•˜๊ธฐ

import converter as cvt

miles = cvt.kilometer_to_miles(150)
print('150km = {}miles'.format(miles))


pounds = cvt.gram_to_pounds(1000)
print('1000g={}pounds'.format(pounds))

 

4. ๋ณ„๋ช… ์‚ฌ์šฉํ•˜๊ธฐ2

from converter import kilometer_to_miles as k_to_m #as ์‚ฌ์šฉ

miles = k_to_m(150)
print('150km={}miles'.format(miles))