python
문자열 포맷팅
hs_seo
2014. 12. 24. 11:29
[string 포맷팅]
python 의 문자열 포맷팅은 두가지 방법을 사용한다.
- .format()
- %
두가지 방법중 어떤 방법을 사용해도 상관없다.
% 를 이용하는 것이 권장되고 있는 것 같다.
<소스코드>
#!/usr/bin/python
# format 이용
# format 에 리스트와 dict 를 이용한 방법
# % 와 dict 를 이용한 방법
# % 와 튜플을 이용한 방법 |
<참고>
http://www.diveintopython.net/native_data_types/formatting_strings.html
https://infohost.nmt.edu/tcc/help/pubs/python/web/new-str-format.htmlhttp://stackoverflow.com/questions/5082452/python-string-formatting-vs-format
https://docs.python.org/2/library/stdtypes.html#str.format
반응형