python - Invalid syntax for print function in for loop -
Today I'm learning "for loop" in Python. I type the code into the Python Shell and after the But when I write code, Notepad and Do the wrong with the third "print" function? In interactive Python shells, It is necessary to leave an empty line between the end of the outer line if / else / for / while / whatever block and the beginning of the next statement. As a simple example: No empty line does not generate an error Is: Reasons to leave an empty space: Generally, do not try to start new statements on "continuations" that begin with "..." Unless you "gt; & gt; & gt; See, press enter until then, and then you can go. SyntaxError: invalid syntax function
print ("I have finished") the word
print appears in red Word for word in the word = ["cat", "125", "dog", "pig"]: if word == "125": print ("no spam spam! Print" ("good" + word) ) Other: Print ("I'm lucky: not spam") Print ("I've finished")
*. Py < / Co De> and it works correctly by running from the command prompt and comes:
Good cat please not spam! I
Other: Print ("I'm lucky: not spam") Print ("I've finished")
& gt; & Gt; & Gt; If true: ... print ("!") ... print ("finished") file "& lt; stdin & gt;", line 3 print ("expired") ^ syntax error: invalid syntax
& gt; & Gt; & Gt; If true: ... print ("!") ...! & Gt; & Gt; & Gt; Print ("Ended") Ended
Comments
Post a Comment