반응형

서문

파이썬에서 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)'

 

 

반응형

+ Recent posts