아이디어는 당신이 공부를 시작해야합니다, 당신은 파이썬을 사용하기 시작하고 당신은 쉽게, 그러나
print("The name is %s!" % names[1])
대신
print("The name is " + names[1] + "!")
같은 더 복잡한 출력을 만들 수 있도록하는 것입니다
new string formatting syntax 바로 알기 :
print("The name is {}!".format(names[1])
물론이 예제에는 문자열 서식 지정 방법의 진정한 힘. 당신은 (예를 들어, 위의 링크 된 문서에서 가져온), 사람들과 더 많은 작업을 수행 할 수 있습니다
>>> '{0}{1}{0}'.format('abra', 'cad') # arguments' indices can be repeated
'abracadabra'
>>> coord = {'latitude': '37.24N', 'longitude': '-115.81W'}
>>> 'Coordinates: {latitude}, {longitude}'.format(**coord)
'Coordinates: 37.24N, -115.81W'
>>> coord = (3, 5)
>>> 'X: {0[0]}; Y: {0[1]}'.format(coord)
'X: 3; Y: 5'
>>> # format also supports binary numbers
>>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)
'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010'
등등 ...
참고 "% s"% names [1]은 (는) str (이름 [1])과 동일하며 names [1]이 (가) 이미 str 인 경우 아무 작업도 수행하지 않습니다. 자세한 내용은 http://docs.python.org/2.7/library/stdtypes.html#string-formatting을 참조하십시오. –