Chapter 2: Write Your First Python Program – A Beginner’s Guide

Kolitha BandaraKolitha Bandara
3 min read

Now we are going to write our 1st program using Python.

I’m creating a new folder for that. I’m naming the folder as “Python”.
You can create a folder named what you like. It doesn’t matter.
Like this;

Now I’m opening this folder in my “VS Code”.
There are so many methods to open your working directory on VS Code. You can use a terminal too.
In this time I’ll show you how to use a terminal for open your working directory in VS Code.

Opening VS Code from our directory

Method 1 :

First, open your folder like this;

Then right-click on any empty space inside the folder. Then you’ll get a menu. Now you can see there is an option to click “Open in Terminal”. Now click it. After that, you’ll get a window like this;

This is a “Terminal”. We call it “Windows PowerShell”. Now it is open in your current directory.
Now type “code .” and hit the Enter key. Don’t forget the space between the code and the pulstop.
Type it like this;

After hitting Enter, you can see it’s opening our VS Code on that selected directory. Then you can close your terminal. Your VS Code is opening like this;

Method : 2

Open your “Python” folder like this;

Then click the address bar of your window and clear the current path like this;

Now, type “cmd” and hit enter like this;

Now you have opened your current directory using the terminal. You can see your terminal like this;

Then type “code .” and hit enter. Like this;

Now you have opened your VS Code. Like this;

Please be confused for the UI. I have customized my VS Code. So your view and my view are different. It’s okay. It doesn’t matter for our journey. You can customize your VS Code too. If you wanna know about my VS Code customizations, please comment it on the comment section.

Creating 1st Python file

You have to create a new file inside your directory. How can we do that? You can use your VS Code directly for that.

Open the “Explorer” tab in your VS Code like this;

Now, right-click on the empty area of that Explorer tab. Then you will get a menu like this;

Now, click the “New File” option from it. Then you’ll get a new empty file like this;

And you can give a name to that file what you want. Like this;

But it’s not complete, why? Because this file doesn’t have an extension yet. So, you have to give an extension for this file. I think you know what the extensions look like. (Ex: .mp3, .mp4, .jpeg, .png …and more) But we use a different kind of extension for this. Why? This is Python. If you wanna write and run a Python file. You have to give a Python extension for that. You can give it like this;

“.py” is the extension of Python. Don’t forget that. Okay, now we have created a Python file. Now we have to open it and write some kind of code as our 1st program. Let’s do that.

Open your Python file and type print(“Hello World”) like this;
(Forget about the code syntax for a moment, we’ll discuss it in the future)

Don’t forget to save your file after editing the file. You can save your file using short cut.
You can use ctrl + s for that. After saving your file, you can run your Python code and you can see an output like this;

This is our 1st Python program. I know, I know, it’s too easy. But stay calm, we can try hard things in the future, buddy…😏

I’ll see you in the next chapter to talk about Python variables…❤️

0
Subscribe to my newsletter

Read articles from Kolitha Bandara directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kolitha Bandara
Kolitha Bandara

I'm a self-learner ❤️