An IDE is primarily a place for writing and running code. They are designed to give you a fast loop between editing a file and checking that the code you just wrote worked and so they provide an easy way of doing this.
New. This will pop up a small box which a common interface in PyCharm. In the pop-up, select
Python file. This will open a second pop-up in which you can set the name of the file. In this case type
first.py in the box and press enter.
Press "New file" under "Start" on the welcome screen or go to
New File. This will create a new file in your folder with a name like
Untitled-1.txt. The first thing we want to do is rename it to have a
.py extension so that VS Code knows that it is a Python file. Go to
Save as... and name the file
At this point, since VS Code has recognises the
.py extension it will start asking you questions about Python tools.
It may pop up a window in the bottom-right saying
The 'Python' extension is recommended for this file type. In this case, press
If it asks you about "Linter pylint is not installed." then select "Install". Likewise for any other Python tools it asks about.
We're going to start with a very simple file so for now, just put the following code into the file:
Now that the Python file has some code in it, we are going to ask the IDE to run the script. In the past you may have run your Python code by typing
python first.py in a terminal or by writing it in a cell in a Jupyter Notebook. IDEs provide a similar and simple way of running your scripts.
Run.... This will pop up a box with
Run as the title and
Edit configurations... and
first as options. Select
first as this is telling PyCharm that you want to run the script
first.py without any extra configuration.
If you don't see
first as a option in the popup then it is likely because PyCharm is still scanning your files. Give it a minute or two and try again.
To run the script, press the green triangular play button in the top-right.
This will run the script and give the output in a tab at the bottom. You should see the word
Change the script to print a different string and re-run it. Make sure that you see your new string printed to the output.