딕셔너리 값 출력할때 {}이랑 ' 없애는법좀 알려주세요
조회수 615회
예를 들어서 i = { '홍길동' : '20살'}
이라고하면 print(i)
하면 { '홍길동' : '20살'}
이렇게 나오잖아요
이걸 '홍길동' : '20살'
이렇게나
홍길동 : 20살
이렇게 깔끔하게 나오게 하는법 없나요?
1 답변
-
>>> s = "%s"%(i) >>> s "{'홍길동': '20살'}" >>> s[1:-1] "'홍길동': '20살'" >>> "%s"%(i)[1:-1] Traceback (most recent call last): File "<pyshell#19>", line 1, in <module> "%s"%(i)[1:-1] TypeError: unhashable type: 'slice' >>> ("%s"%(i))[1:-1] "'홍길동': '20살'" >>> print(("%s"%(i))[1:-1]) '홍길동': '20살'
>>> for e in i.items(): print(e) ('홍길동', '20살') >>> for e in i.items(): print(*e) 홍길동 20살 >>> for e in i.items(): print(':'.join(e)) 홍길동:20살
댓글 입력