print SyntaxError: invalid syntax 오류 문제
2010-05-10 15:19
Print Is A Function The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105). Examples:
view source print ?
01 Old: print "The answer is" , 2 * 2 02 New: print ( "The answer is" , 2 * 2 ) 03
04 Old: print x, # Trailing comma suppresses newline 05 New: print (x, end = " " ) # Appends a space instead of a newline 06
07 Old: print # Prints a newline 08 New: print () # You must call the function! 09
10 Old: print >>sys.stderr, "fatal error" 11 New: print ( "fatal error" , file = sys.stderr) 12
13 Old: print (x, y) # prints repr((x, y)) 14 New: print ((x, y)) # Not the same as print(x, y)! You can also customize the separator between items, e.g.:
view source print ?
1 print ( "There are <" , 2 * * 32 , "> possibilities!" , sep = "") which produces: There are <4294967296> possibilities! Note: * The print() function doesn’t support the “softspace” feature of the old print statement. For example, in Python 2.x, print "A", "B"would write "AB"; but in Python 3.0, print("A", "B") writes "A B". * Initially, you’ll be finding yourself typing the old print x a lot in interactive mode. Time to retrain your fingers to type print(x) instead! * When using the 2to3 source-to-source conversion tool, all print statements are automatically converted to print() function calls, so this is mostly a non-issue for larger projects.
작업은 다음과 같습니다.
>>>
print
"
Hello World!
"
File
"
<stdin>
"
, line
1
print
"
Hello World!
"
^
SyntaxError: invalid syntax
>>>
오류 원인:python v3.0 이후 버전에서 v2.x 버전의 print를 print () 로 변경합니다.그래서 여기서 print를 호출합니다("Hello World!").성공할 수 있다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.