봐 here. 함수는 괄호를 열고 닫음으로써 특징 지어진다.
예. 파이썬 2에서
str.split()
list.reverse()
list.insert(0, 'hi')
, 다음 구문 괜찮을 것 :
$ python2
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> num = 78
>>> print 'The number is %d' %(num)
The number is 78
>>>
그러나, 파이썬 3에서, print
함수이기 때문에, 당신은 열고 닫는 괄호가 필요합니다
$ python3
Python 3.4.0b2 (v3.4.0b2:ba32913eb13e, Jan 5 2014, 11:02:52)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> num = 78
>>> print 'The number is %d' %(num)
File "<stdin>", line 1
print 'The number is %d' %(num)
^
SyntaxError: invalid syntax
>>> print('The number is %d' %(num))
The number is 78
>>>
을
해야 할 일 :
formatter="%r%r%r%r"
print(formatter % (1,2,3,4))
실제로 문자열 형식을 지정하는 방법은 [here] (https://docs.python.org/2/library/string.html#formatstrings)를 참조하십시오. 그러나 HeavyLight의 대답은 인쇄가 실패한 이유입니다. – aruisdante