Python/์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜

[python] packing & unpacking ๋ฆฌ์ŠคํŠธ, ํŠœํ”Œ

์ฃผ์˜ ๐Ÿฑ 2022. 11. 10. 14:50
728x90
๋ฐ˜์‘ํ˜•

ํŠœํ”Œ ์–ธํŒจํ‚น ์˜ˆ์‹œ - ๋ฆฌ์ŠคํŠธ๋Š” ()๋ฅผ []๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋ฆฌ์ŠคํŠธ ํŒจํ‚น, ์–ธํŒจํ‚น์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

a, b = (1, 10)
print(a)
print(b)

1

10

a, *b, c = (1, 2, 3, 4, 5)
print(a)
print(b)
print(c)

1
[2,3,4]
5

 

*์€ ๋‚˜๋จธ์ง€๋ฅผ ๋ฌถ์–ด์ค€๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ํŽธํ•˜๋‹ค.

 

๋ฐ˜์‘ํ˜•