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 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")

But when I write code, Notepad and *. Py < / Co De> and it works correctly by running from the command prompt and comes:

  Good cat please not spam! I   

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.

  Other: Print ("I'm lucky: not spam") Print ("I've finished")   

As a simple example: No empty line does not generate an error Is: & gt; & Gt; & Gt; If true: ... print ("!") ... print ("finished") file "& lt; stdin & gt;", line 3 print ("expired") ^ syntax error: invalid syntax

Reasons to leave an empty space:

  & gt; & Gt; & Gt; If true: ... print ("!") ...! & Gt; & Gt; & Gt; Print ("Ended") Ended   

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.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -