#λͺ¨λ
#λͺ¨λμ νμν κ²λ€λΌλ¦¬ λΆνμ²λΌ λ§λ€μ΄μ§ νμΌ
# ex. μλμ°¨ μ΄μ© ν νμ΄μ΄ νν¬λλ©΄ νμ΄μ΄λ§ κ΅μ²΄νλ©΄ λ¨
#λͺ¨λμ νμ₯μλ .py
#νκΈλ§ λ°λ μνκ΄, μλμ μκ±°μ¬λ¬μ€.
# μΌλ° κ°κ²©
def price(people):
print("{0}λͺ
κ°κ²©μ {1}μ μ
λλ€.".format(people, people * 10000))
#μ‘°μ‘°ν μΈ κ°κ²©
def price_morning(people):
print(("{0}λͺ
μ μ‘°μ‘°ν μΈ κ°κ²©μ {1}μ μ
λλ€.".format(people, people * 6000)))
#κ΅°μΈ ν μΈ κ°κ²©
def price_soldier(people):
print(("{0}λͺ
μ κ΅°μΈν μΈ κ°κ²©μ {1}μ μ
λλ€.".format(people, people * 4000)))
μ¬κΈ°κΉμ§κ° theater_module
-----------------------------
μ΄ν λͺ¨λμ μ¬μ©
import theater_module
theater_module.price(3) #μ
μ΄μ μν κ°κ²©
theater_module.price_morning(4)
theater_module.price_soldier(5)
import theater_module as mv #mvλ‘λ§ theater_module νΈμΆ κ°λ₯ / λͺ¨λλͺ
κΈΈλ μ€μ¬μ
mv.price(3)
mv.price_morning(4)
from theater_module import *
#from random import *
price(3)
price_morning(4)
from theater_module import price, price_morning #μ΄λ€ ν¨μλ§ κ°λ€μΈμ§ μ μνκΈ°
price(5)
from theater_module import price_soldier as price #λ³λͺ
μ priceλΌκ³ ν κ±°μΌ.
price(5) #κ΅°μΈ κ°κ²©μ λνλ
# ν¨ν€μ§ : λͺ¨λμ λͺ¨μλ μ§ν©, νλμ λλ ν 리μ μ¬λ¬ λͺ¨λλ€μ κ°λ€λ κ²
# μ κ· μ¬νμ¬ νλ‘μ νΈ(νκ΅, λ² νΈλ¨ ν¨ν€μ§ μν μ 곡)
# ν λλ ν 리μ λ§λ€κ³ μνλ λͺ¨λκ³Ό __init__ λͺ¨λμ λ§λ λ€
thailand.py
class ThailandPackage:
def detail(self):
print("[νκ΅ ν¨ν€μ§ 3λ° 5μΌ] λ°©μ½, ννμΌ μ¬ν(μΌμμ₯ ν¬μ΄) 50λ§")
vietnam.py
class VietnamPackage:
def detail(self):
print("[λ² νΈλ¨ ν¨ν€μ§ 3λ° 5μΌ] λ€λ ν¨λ μ¬ν 60λ§")
practice
import travel.thailand #μν¬νΈλ λͺ¨λμ΄λ ν¨ν€μ§λ§ κ°λ₯, ν΄λμ€λ μλ¨
trip_to = travel.thailand.ThailandPackage()
trip_to.detail()
from travel import vietnam
trip_to = vietnam.VietnamPackage()
trip_to.detail()
__init__
__all__ = ["vietnam", "thailand"] #μ¬μ© κ°λ₯ν λ²μλ₯Ό μ€μ ν΄μ£Όλ κ²
λͺ¨λ μ§μ μ€ν
if __name__ == "__main__":
print("Thailand λͺ¨λμ μ§μ μ€ν")
print("μ΄ λ¬Έμ₯μ λͺ¨λμ μ§μ μ€νν λλ§ μ€νλΌμ")
trip_to = ThailandPackage()
trip_to.detail()
else:
print("Thailand μΈλΆμμ λͺ¨λ νΈμΆ")
ν¨ν€μ§, λͺ¨λ μμΉ
import inspect
import random
print(inspect.getfile(random))
print(inspect.getfile(thailand))
λ΄μ₯ν¨μ
# dir : μ΄λ€ κ°μ²΄λ₯Ό λ겨쀬μ λ κ·Έ κ°μ²΄κ° μ΄λ€ λ³μμ ν¨μλ₯Ό κ°μ§κ³ μλμ§ νμ
print(dir())
import random
print(dir())
# print(dir(random))
lst = [1, 2, 3]
print(dir(lst))
name = "Jim"
print(dir(name))
list of python builtins κ²μ
μΈμ₯ν¨μ
# νμ΄μ¬μμ μ λ§μ μΈμ₯ν¨μ μ 곡 μ€
# list of python modules κ²μν΄μ λͺ¨λ κ²μ κ°λ₯
# glob : κ²½λ‘ λ΄μ ν΄λ / νμΌ λͺ©λ‘ μ‘°ν (μλμ° dir)
import glob
print(glob.glob("*.py")) #νμ₯μκ° pyμΈ λͺ¨λ νμΌ
# os : μ΄μ체μ μμ μ 곡νλ κΈ°λ³Έ κΈ°λ₯
import os
print(os.getcwd()) #νμ¬ λλ ν 리
folder = "sample_dir"
if os.path.exists(folder):
print("μ΄λ―Έ μ‘΄μ¬νλ ν΄λμ
λλ€")
os.rmdir(folder)
print(folder, "ν΄λλ₯Ό μμ νμμ΅λλ€.")
else:
os.makedirs(folder) #ν΄λ μμ±
print(folder, "ν΄λλ₯Ό μμ±νμμ΅λλ€.")
# time : μκ° κ΄λ ¨ ν¨μ
import time
print(time.localtime())
print(time.strftime("%Y-%m-%d %H:%M:%S"))
import datetime
print("μ€λ λ μ§λ ", datetime.date.today())
# timedelta : λ λ μ§ μ¬μ΄μ κ°κ²©
today = datetime.date.today() #μ€λ λ μ§ μ μ₯
td = datetime.timedelta(days=100) #100μΌ μ μ₯
print("μ°λ¦¬κ° λ§λμ§ 100μΌμ", today + td)
# Quiz) νλ‘μ νΈ λ΄μ λλ§μ μκ·Έλμ²λ₯Ό λ¨κΈ°λ λͺ¨λμ λ§λμμ€
#
# 쑰건 : λͺ¨λ νμΌλͺ
μ byme.pyλ‘ μμ±
#
# (λͺ¨λ μ¬μ© μμ )
import byme
byme.sign()
# (μΆλ ₯ μμ )
# μ΄ νλ‘κ·Έλ¨μ irisμ μν΄ λ§λ€μ΄μ‘μ΅λλ€.
# μ νλΈ : www.youtube.com
# μ΄λ©μΌ : saltedcaramel.macarons@gmail.com
μ€ννμΌ.py
import byme
byme.sign()
byme.py
def sign():
print("μ΄ νλ‘κ·Έλ¨μ irisμ μν΄ λ§λ€μ΄μ‘μ΅λλ€.")
print("μ νλΈ : www.youtube.com")
print("μ΄λ©μΌ : saltedcaramel.macarons@gmail.com")
'Coding > Python' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Python] *args, **kwargs (0) | 2021.12.30 |
---|---|
[python] list Comprehension, μΌν μ°μ°μ (0) | 2021.12.29 |
[python] μμΈμ²λ¦¬ ν΄μ¦ (0) | 2021.11.04 |
[python] μμΈ μ²λ¦¬ (0) | 2021.11.04 |
[python] ν΄λμ€ ν΄μ¦ (0) | 2021.11.03 |