In this python tutorial, we will build our first traditional Python Hello world program. I have installed python version 3.8.2 and Pycharm version 2020.1 as the code editor which we will use to build the first program.
So in my last blog we discussed how can we install python3 in different operating system and we saw the installation of different code editors and IDEs used to write the python code.
If you didn’t go through that you can see once Python download and Installation steps (Windows 10/Unix/Mac/Ubuntu/CentOS ).
Python Hello World program using python 3.8 and Pycharm 2020
Now our python is installed and code editor (Pycharm) is also installed in my machine. Both are with the latest version as of April 2020. Let’s start our first program.
Open the Pycharm code editor
Now next is click on “Create New Project” button.
Now in this step first give a meaning full name to the project. I gave the name as “Helloworld”. You can change your preferred location also. Base Interpreter will be populated automatically. Now please click on the create button.
Now the below popup will appear, you can just close the tip of the day pop up.
Now the below popup shows some helpful information. See once. One more important thing among these is you can drag and drop a file there so that it will open.
In this step Click on File –> New Scratch file.
Now choose “Python” from the New scratch file pop up.
Now see below one python file with name scratch.py got created.
Now give a meaning full name to the file. So we need to rename this file. Right-click on the Scratch.py and select the Rename file.
Below Rename pop up will appear, Give a Proper name. In this case I gave the name as Helloworld.py. Then click on the Refactor button.
Now, see the file name has been renamed to “Helloworld.py”. So now our empty python file is ready.
Now write the below code in the Helloworld.py file and then Click on run –> Run option. You can also use keyboard shortcut Alt+Shift+F10 to run the file.
Oops, While executing the above code,It throws me the below error
Traceback (most recent call last): File "C:/Users/Bijay/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/Helloworld.py", line 1, in <module> Print('Hello world!!') NameError: name 'Print' is not defined
Any guess why the above error. This is because We entered the print as Print(caps P). The correct one should be print().
Note: Python is case sensitive.
So the correct line of code is as below.
Now enter the above code and run the file. Let’s see what’s happening. Now if you will notice here the run option is Run”HelloWorld” that means Run””Filename.
Now when I changed the Print(caps P) to print(). If you will see below the auto-suggestion box showing print function displayed.
Now let’s run the program.
Congratulations, Yes I got the expected output with out any error this time. See below.
Run your Python file from the command prompt
There is one more approach to run your python file form your command prompt if you don’t have Pycharm installed in your machine.
Open your command prompt and go to the path where your python file is present. To do so use the below command and press enter.
Note: C:\Users\Bijay\AppData\Roaming\JetBrains\PyCharmCE2020.1\scratches is the path for me where my HelloWorld.py file presents. So I need to go to that path and execute the code.
Now put file name i.e Helloworld.py and press enter. See below we got the expected output.
You may like following below Python Tutorials:
- What is Python and What is the main use of Python?
- Why python is so popular? Why python is booming?
- How does python work? how python is interpreted?
- Python Variable (An easy Guide)
- Python download and Installation steps
- Python sort list of tuples
- Python While Loop Example
- String methods in Python with examples
Here in this tutorial, We have completed developing our first hello world program using python version 3.8 and Pycharm version 2020.1 as a code editor.
Python is the best!!!!!
This python tutorial explains the below points:
- How to create a Python Hello World program using python 3.8 with Pycharm 2020 code editor?
- Run your Python file from the command prompt.