๋ชจ๋(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))
'๐์น ๊ฐ๋ฐ(Web) > ๐ํ์ด์ฌ(Python)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ์ด์ฌ ๋๋ค random ๋ชจ๋ (0) | 2023.02.01 |
---|---|
ํ์ด์ฌ ํ์ค ๋ชจ๋ (0) | 2023.02.01 |
ํ์ด์ฌ ํจ์(function) (0) | 2023.01.30 |
ํ์ด์ฌ ๊ต์งํฉ intersection() ํฉ์งํฉ union() ์ฐจ์งํฉ difference() (0) | 2023.01.30 |
join ๋ฉ์๋ /split ๋ฉ์๋ /replace ๋ฉ์๋ /strip(), lstrip(), rstrip() ๊ณต๋ฐฑ ์ ๊ฑฐ (0) | 2023.01.30 |