본문 바로가기
Programming/Python

string unpacking - 문자열 언팩킹

by Chan_찬 2020. 8. 23.
728x90
반응형

python - unpacking

언팩킹이란? 요소를 여러 변수에 나누어 담는 것

locals()? 현재 scope 에 있는 local 변수를 딕셔너리 type( {key:value} ) 으로 반환

>>> nums = [1,2,3,4]

# unpacking
>>> a,*b = nums
>>> a
1
>>> b
[2,3,4]

>>> f'{a} {b} {nums}'
1 [2,3,4] [1,2,3,4]

# unpacking
>>> '{a} {b} {nums}'.format(**locals())
1 [2,3,4] [1,2,3,4]
728x90
728x90
BIG
Buy me a coffeeBuy me a coffee

댓글