+ 2

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

23rd Jun 2019, 11:07 PM
Tobias Fuentebuena Guardón
Tobias Fuentebuena Guardón - avatar
6 Réponses
+ 5
add \n in the string. It will create a new line in most languages
23rd Jun 2019, 11:08 PM
Jax
Jax - avatar
+ 1
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.)
24th Jun 2019, 4:24 AM
Anna
Anna - avatar
0
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
23rd Jun 2019, 11:20 PM
Tobias Fuentebuena Guardón
Tobias Fuentebuena Guardón - avatar
0
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
23rd Jun 2019, 11:59 PM
Tobias Fuentebuena Guardón
Tobias Fuentebuena Guardón - avatar