Unexpected Indent Error


hi all, i was wondering if any one can help. installed python 2.7.14 for Windows. It prompts me with >>> i start typing something def bigger ( first, second) Then I want to start a new line to enter print max (first, second) but it gives me an indentation error. Not sure how to get out of that. Tried \n tried \ neither works. please help. how do i start a new block?


If you are typing in block code (function, loop) from the interactive command line, then don’t add any spaces or tabs. Just hit Enter to move to a new line. The editor will insert the indent for you.

>>> def bigger(first, second):
	return first if first > second else second

>>> bigger(2, 4)
>>> bigger(5, 1)

Working in the interactive console is not very efficient, as coding goes since it is command line entry. The function is stored in memory but would be better written in a savable file. In the File menu of the interactive console, click New File. This will open a new window with a text editor that you can compose in. Save your file then in the Run menu, click Run (or press F5).


Thanks so much for the prompt response ( and my apologies I am responding so late). I realized I was missing the parentheses.I just tried again and it worked as supposed to. The only thing that’s almost disheartening is that even one tine mistake will make you restart the shell all over the again! There is virtually no way to go back delete the mistake and carry on =[


If you are working directly in the interactive console, then once a mistake is discovered, you need to go back to that line, set the cursor at the end, hit Enter, and the line or lines will appear at the prompt, ready for editing. All the lines that would have followed this one will also have to be re-entered, (Enter, Enter) in their correct order.

As for working with the text editor, changes need to be saved before we can run them, and that will restart the shell but won’t erase anything that is present. Anytime you F5 a page in the editor, the shell will restart.

Working with functions is much smoother, since we can compose each function and test it with dummy arguments, fix it and then leave it in memory. (Don’t Run anything from the editor, though or it will be lost with the restart.) Just as we can store functions and objects (data structures, and so on) in JavaScript’s console, we can do the same in the shell.

Still, the editor is the place to organize and store code so it is never lost. I usually save and run at first, but for tweaking of functions, I grab one, paste it in, edit it, and then Enter, and call it with appropriate dummy data (or that present in memory from the Run) to see if any errors are thrown. Once I like the function (for now) I copy it back to the editorfile and Save it, using a version number in most cases.