Learn to execute simple Python commands from within the VS Code IDE, as well as exploring the user interface and its features.
- Let's take a look at a few ways we can run our Python programs in VS Code. Let's go ahead and open up our Exercise Files folder. To do that, we're going to click on Open Folder, and then we're going to choose Exercise Files. Now the first thing you'll notice over here on the explorer pane is that we have a list of all of the folders inside of our Exercise Files directory, but there's this one folder that we didn't create, .vscode. You don't have to worry about changing anything here for the course. This is just a special folder created by VS Code in order to store some metadata. Let's go ahead and open up one of the files. We're going to open the one inside of chapter 02, and we're going to choose 02_07. This looks really different from what we've seen before in our simple text editor. The first thing you notice is the use of line numbers over here on the left side. We call this the gutter. Using line numbers inside of IDEs makes it easier for us to find codes later on. For example, on line number three, we have the print statement, goodbye world. What's another thing you notice that's really different? It's the use of color. We call this syntax highlighting. This is how we can point out special key words or various objects inside of our programs. For example, the print key word is yellow, whereas the hello world is orange, but how did VS Code know to choose the colors for the Python programming language? Well it's based on the fact that we're using the .py file extension. This is the file extension used for Python code. Now let's say we want to run this code. We can click anywhere inside of our file, right-click, and go to Run Python File In Terminal. Let's do that now. Notice that we see our output. Hello world, goodbye world. We've done this using our IDE. Now what if we were interested in running all of the code in a file? Well we could even use just one portion. For example, let's run line number three only. We'll come to this line, right-click, and we'll choose Run Selection or Line in Python Terminal, and now we only get goodbye world. What's really nice is that this actually watches a real Python shell for us. So if we want, we could even run other Python commands. For example, four star four. This is how we do multiplication in Python. When we hit enter, we get 16. Now let's go ahead and exit this the same way we would our normal terminal from the command line. We're going to type exit, and we're no longer inside of our Python prompt, and to leave this entire area, we can just click the close button that's in the right corner. Great. And that's it. We've seen a few different ways that we can run our Python programs inside of VS Code, and it's nice that we have such helpful features like the line numbers or the syntax highlighting. I encourage you to explore running some simple commands on your own so that you can get the hang of it.
- Writing source code
- Basic statements and expressions
- Working with numbers and strings
- Writing conditional code
- Increasing your efficiency with functions
- Working with comments
- Making decisions in code
- Troubleshooting errors
- Learning about other languages