How to make this Python program compile?

I have this Python code:

import re s = "aa67bc54c9" for t, n in re.findall(r"([az]+)([0-9]+)", s) 

And I get this error message when I try to run it:

  File "<stdin>", line 1 for t, n in re.findall(r"([az]+)([0-9]+)", s) ^ SyntaxError: invalid syntax 

How can i solve this? I am new to Python.

+4
source share
2 answers

You will need a colon ( : at the end of the line.

And after this line, you will need the indentation of what to actually do in the loop. If you don't want to do anything in the loop (perhaps until you get more code written), you can use the pass statement to indicate basically no-op.

In Python, you will need a colon at the end

  • for operators
  • while
  • if / elif / else statements
  • try / except statements
  • Operator class instructions
  • def (function)
+4
source

for starts the loop, so you need to end the line with : and put the body of the loop indented in the following lines.

EDIT:

For more information, I suggest you go to the main documentation .

+7
source

All Articles