λͺ¨λ
β’
λͺ¨λ
β’
import
β’
νμ€λͺ¨λ
λͺ¨λ
λ³μλ ν¨μ λλ ν΄λμ€λ‘ λͺ¨μλμ νμ΄μ¬ νμΌ
import
λͺ¨λμ ν¬ν¨νλ ν€μλ
β’
λͺ¨λ ν¬ν¨νκΈ°
β’
λͺ¨λ λ΄λΆμ μΌλΆ(ν¨μ)λ§ ν¬ν¨νκΈ°
λͺ¨λ ν¬ν¨νκΈ°
import λͺ¨λ
import λͺ¨λ as λ³λͺ
λͺ¨λ λ΄λΆμ μΌλΆ(ν¨μ)λ§ ν¬ν¨νκΈ°
from λͺ¨λ import ν¨μ
from λͺ¨λ import ν¨μ1, ν¨μ2
from λͺ¨λ import *
νμ€λͺ¨λ
νμ΄μ¬μ 곡μ λ°°ν¬μ ν¬ν¨λ λͺ¨λκ³Ό ν¨ν€μ§μ λͺ¨μ
λν νμ€ λͺ¨λ
os, sys, datetime, random, json, urllib, math λ±
νμ΄μ¬ νμ€ λΌμ΄λΈλ¬λ¦¬μλ λ€νΈμν¬ ν΅μ , λ°μ΄ν° μμΆ, λ°μ΄ν°λ² μ΄μ€ κ΄λ¦¬, νμΌ μ²λ¦¬, λ μ§ λ° μκ° μ²λ¦¬, μν ν¨μ λ± λ€μν κΈ°λ₯μ΄ ν¬ν¨λμ΄ μμ΅λλ€. μ΄λ¬ν λͺ¨λλ€μ νμ΄μ¬ κ°λ°μ ν¨μ¬ λ ν¨μ¨μ μ΄κ³ κ°λ ₯νκ² λ§λ€μ΄ μ€λλ€.
λͺ¨λ | μ€λͺ
|
math | μν μ°μ°κ³Ό κ΄λ ¨λ ν¨μλ₯Ό μ 곡νλ λͺ¨λ |
random | λμ(λλ€ μ)λ₯Ό μμ±νλ λͺ¨λ |
time | μκ° μ²λ¦¬μ κ΄λ ¨λ ν¨μλ₯Ό μ 곡νλ λͺ¨λ |
datetime | λ μ§/μκ° λ°μ΄ν°λ₯Ό μ²λ¦¬νλ λͺ¨λ |
μ§μ λ§λ λͺ¨λ μ¬μ©νκΈ°
converter.py
MILES = 0.6213
POUND = 0.0022
# ν¬λ‘λ―Έν°λ₯Ό λ§μΌλ‘ λ³ννλ ν¨μ
def kilometer_to_miles( kilometer ):
return kilometer * MILES
# κ·Έλ¨μ νμ΄λλ‘ λ³ννλ ν¨μ
def gram_to_pound( gram ):
return gram * POUND
Python
볡μ¬
main.py
β’
import converter λ‘ ν¬ν¨ν λ
# converter λͺ¨λ
# : κ·κ²©μ΄λ λ¨μλ₯Ό λ³ννλ ν¨μλ₯Ό μ 곡νλ λͺ¨λ
import converter
# from converter import *
# 150km --> miles λ‘ λ³ν
miles = converter.kilometer_to_miles(150)
print( '150km = {} miles'.format(miles) )
# 1000g --> pound λ‘ λ³ν
pound = converter.gram_to_pound(1000)
print('1000g = {} pound'.format(pound) )
Python
볡μ¬
import converter as c
μμ κ°μ΄ ν¬ν¨νλ©΄, μλ μ²λΌ λ¨μΆν΄μ μΈ μμλ€.
converter.kilometer_to_miles(150) β‘ c.kilometer_to_miles(150)
Python
볡μ¬
β’
from converter import * λ‘ ν¬ν¨ν λ
# converter λͺ¨λ
# : κ·κ²©μ΄λ λ¨μλ₯Ό λ³ννλ ν¨μλ₯Ό μ 곡νλ λͺ¨λ
# import converter
from converter import *
# 150km --> miles λ‘ λ³ν
miles = kilometer_to_miles(150)
print( '150km = {} miles'.format(miles) )
# 1000g --> pound λ‘ λ³ν
pound = gram_to_pound(1000)
print('1000g = {} pound'.format(pound) )
Python
볡μ¬