Write First Python Program

Write First Python Program

In the last chapter, we have learned how to install the python, run and check the python version. In this Article we will write our first python program and how to execute python and use VS Code like a pro with help of this usefull settings about vscode editor So lets start.

When we open a command prompt and type Python then that environment which we see is called python interpreter- which is a program that executes the python program code.

We can type our code in a file and give it to interpreter or type python code direct here. So to write our Python code we need an editor or IDE, for this course, I will use VS Code editor. Download and install the VS Code editor if you don’t have the editor.

Open the VS Code editor and on the top click on file menu then clicks on the open folder and create a new folder in your computer with the name HelloWorld and select that folder so it will be available in your VS Code editor.

First Python Program

Now click on the top left double-file icon to open the explorer where your all project folder and the file will be displayed. Create a new file inside the HelloWorld projecct folder and name the file 'app.py'

Write your first Python code

print("hello world")

Type ctrl + ~ to open the integrated terminal in VS Code to run the python code. In terminal type python or py and name of your file "py app.py" and press enter to run the code. You will get the hello world message in the terminal.

Now press ctrl+` to hide the integrated terminal and write another code

print("hello world")
Print("$" * 10)

Open an integrated terminal and run the code by typing python and name of your file "python app.py" and see the result $ have repeated ten times. You have notice Instruction of the program executed top to bottom.

Python Extension for IDE

Now we will convert this VS Ccode editor to powerful IDE using python extension with the extension of this plugin we will get Linting, Debugging, Auto-completion, Code Formatting, Unit Testing, and Code Snippets.


So let’s install the python extensions by clicking on the left second last icon and search for python and click on that extension, install and reload the extension after installation if you get the pylint not install error the click on that to install the pylint


Lint in action

Now type invalid code to check how linting is work

print "Hello World"

Save the changes you will notice a red underline in your code if you hover it you will get the tooltips from pylint that is explaining the error. So now you understand the benefits of linting.

Let me tell you a couple of useful shortcut, On the top look at the view menu click on problems (ctrl+shft+M). It will open the problem panel where you will get all issues of your project code in one place. When you work on multiple files, This will be a helpful tool.

Related Articles