Python
In this tutorial we will write our first Hello World Python program.
Lets go ahead and write the "Hello World" program using text editor like Sublime Text and then we will use PyCharm IDE.
Feel free to use any other text editor of your choice.
Lets begin our journey by printing "Hello World" text using Python.
Create a new file by the name HelloWorld.py
and then write the following code inside.
print("Hello World")
We don't have to put semicolon ;
at the end of the line in Python like we do in other programming langauages like C and Java.
Now, open the Terminal (for Mac and Linux) and type the following command.
$ python HelloWorld.py
For Windows, assuming you have Python executable installed on your C:
, run a similar command in the Command Prompt.
c:\pythonXX\python HelloWorld.py
Where, pythonXX
is the Python version you have installed on your machine.
If there was no error then you will get to see the "Hello World" text on your screen.
In the following example we will be using PyCharm Community Edition IDE to write and run our "Hello World" Python program.
When you open the IDE you will see the following. Select the first option 'Create New Project'.
Or, if you are already in a project then click on File then select New Project.
Set the location of your project on your computer and select the base interpreter.
In the following example I have named my project HelloWorld
and selected Python 3.7.
Now right click on the project folder HelloWorld, then select New and then click on Python File.
Now, name the file HelloWorld and click on the OK button.
This will create a new Python file HelloWorld.py
inside the project folder.
Inside the HelloWorld.py file write the following code.
print("Hello World")
Save your program and click on Run and then click on Run 'HelloWorld'.
This will open the in-built Run console of PyCharm IDE and you will get to see the output "Hello World".
And this brings us to the end of this tutorial. In the next tutorial we will dive deep into Python programming langauge.
If you find this tutorial and this website interesting and helpful then do share it on social media with your friends.
See you in the next tutorial. Have fun programming.
ADVERTISEMENT