How can I enter a new line in Python | Sololearn: Learn to code for FREE!


How can I enter a new line in Python

Hello, I've just started the Python Course, so I downloaded the Python IDLE and started to program and practise. When reaching the if statement part, I discovered that I don't know how to write a new line after the if statement that it is not indented. I tried even to copy-paste the code from the example in SoloLearn but it tells me that there is a syntax error. So, how can I enter a new line, make the program read it and not run it? I want to know it for every case, because if I want to declare 2 variables, one above other (to make it easier to read) I can't, because the program starts its execution when I press ENTER, and this is only one example

6/23/2019 11:07:15 PM

Tobias Fuentebuena Guardón

6 Answers

New Answer


add \n in the string. It will create a new line in most languages


Tobias Fuentebuena Guardón xd youre talking about the indentation error, after your if statement, press enter, if the blinking cursor starts from the extreme end press tab If x == x: //your code here


You can write \n or give a print(" ")then it get new line self


Open a new text file, enter your code, save it as <name of your file>.py. Open the file with IDLE (.py files will probably be associated with IDLE), press F5 to run the script. Alternatively edit and run the file in any IDE (PyCharm, Spyder, VS Code etc.)


If I write \n then i will be able to keep coding in the next line if I press ENTER? Or do you mean that this command will make the string to make a line jump? Because I want to do the first one, keep coding without running the program


No, My code indents well. But, por example, when I declare a variable or even I want to keep coding below that if sentence, I receive a code or just execute the program. For example: X == X: //Code... [I want to put something here, outside the if. But I can't, when I press enter the IDLE runs the program]---- if I achieve to reach this line, the code that I write here gives me a syntax error even if I copy-paste it from SoloLearn