반응형
서문
파이썬에서 string format을 지정하는 방식에 대해서 정리해보자
방법
# 1
string = '%s %d' % (STR_VALUE, INT_VALUE)
# 2
VALUE_LIST = [1,2,3,4]
'value {0} {1}'.format(*VALUE_LIST)
# 3
VALUE_LIST = {'name':'abc', 'ok':'ddd'}
'VALUE {name} {ok}'.format(**VALUE_LIST)
# 4
'string : {} int : {}'.format("Something", 100)
# 5
'string : {0} int : {1}'.format("Something", 100)
# 6
'string : {name} int_value : {int_value}'.format(name="abc", int_value=100)
# 7
'string {0} int_value {int_value}'.format("abc", int_value=100)'
반응형
'python' 카테고리의 다른 글
[python] operator interface (0) | 2020.04.08 |
---|---|
[Python] python3으로 업그레이드 (mac) (0) | 2020.02.28 |
[python][pyjwt] JWT example (0) | 2020.02.03 |
[python] AttributeError: module 'yaml' has no attribute 'FullLoader' (0) | 2020.01.30 |
[Python] python3으로 업그레이드 (centos7) (0) | 2020.01.14 |