- λμ λ¬Έassignment statement : a = b /a equal b/
- λμ μassignment expression : a := b /a walrus b/
- λμ λ¬Έμ μ¬μ©ν μ μλ κ²½μ°μ λμ κ°λ₯
if count := fresh_fruit.get('λ λͺ¬', 0):
make_lemonade(count)
else:
out_of_stock( )
pieces = 0
if (count := fresh_fruit.get('λ°λλ', 0)) >= 2:
pieces = slice_bananas(count)
try: # piecesκ° 0μ΄ μλμλ μμΌλκΉ νλ² ν΄λ³ΌκΉ?
smoothies = make_smoothies(pieces)
except OutOfBananas: # μλλ©΄ λ§κ³
out_of_stock()
if (count := fresh_fruit.get('λ°λλ',0)) >= 2 :
pieces = slice_bananas(count)
to_enjoy = make_smoothies(pieces)
elif (count := fresh_fruit.get('μ¬κ³Ό',0)) >= 4 :
to_enjoy = make_cider(count)
elif (count := fresh_fruit.get('λ λͺ¬',0)) :
to_enjoy = make_lemonade(count)
else:
to_enjoy = 'nothing'
bottles = []
while fresh_fruit := pick_fruit( ): # pick_fruit:generator
for fruit, count in fresh_fruit.items():
batch = make_juice(fruit, count)
bottle.extend(batch)
- μ°Έκ³
- appendμ extendμ μ°¨μ΄
- μ ν©μ λμ μμ μ΄ν°λ μ΄ν°, μ λλ μ΄ν°μ ν¨κ» κ°λ ₯νκ² λμνλ κ²μΌλ‘ 보μΈλ€.
Effective Python 2nd μ΄νν°λΈ νμ΄μ¬ : νμ΄μ¬ μ½λ©μ κΈ°μ μ BETTERWAY10μ λ΄μ©μ λλ€.