- Python Hello World Program (Step by Step using Pycharm + Visual Studio Code)
- Python Hello World program using Python 3.8 and Pycharm 2020
- Run your Python file from the command prompt
- Create a hello world program in Python using Visual Studio Code
- What is Visual Studio Code?
- Download and Install Visual Studio Code in Windows 10
- Install Python Extension for Visual Studio Code
- Create hello world program in python using Visual Studio Code
- Conclusion
- Hello World Programming Tutorial for Python
- 🔹 Hello, World!
- 🔸 «Hello, World!» in the Python Shell
- Step 1: Start IDLE
- Step 2: Display the Message
- Step 3: See the Output
- 🔹 «Hello, World!» in a Python File
- Step 1: Create a File
- Step 2: Write the Code
- Step 3: Save the File
- Step 4: Run the Program
- 🔸 Customize Your Program
- 🔹 First Python Program Completed
Python Hello World Program (Step by Step using Pycharm + Visual Studio Code)
In this python tutorial, we will build our first traditional Python Hello world program using Pycharm and Visual studio code. If you want to learn Python as a beginner, then let us create a hello world program in Python using vscode and pycharm.
Any of the editors (Pycharm or Visual Studio Code), you can use for coding in Python.
This is a step by step tutorial to create your first hello world program in Python using Pycharm and Visual Studio Code.
If you want to learn Python and machine learning, join Python and Machine Learning Training Course.
Python Hello World program using Python 3.8 and Pycharm 2020
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.
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 meaningful name to the project. I gave the name “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 the 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 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” which means Run “Filename”.
Now when I changed the Print(caps P) to print(). If you will see below the auto-suggestion box showing the print function displayed.
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.
cd C:\Users\Bijay\AppData\Roaming\JetBrains\PyCharmCE2020.1\scratches
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.
This is how we can create your first hello world program using Python in Pycharm.
Create a hello world program in Python using Visual Studio Code
Now, let us see, how to create a hello world program in python, and also, we will see how to download and install visual studio code in windows 10.
What is Visual Studio Code?
Microsoft provides a Visual Studio Code the free and open-source code editor. It is fast and straightforward. Visual Studio Code supports all three operating systems like Windows, Linux, and macOS.
It has a lot of built-in features like GitHub, debugging and embedded Git control, syntax highlighting, snippets, and intelligent code completion. Also, you can add extensions to create a Python development environment as per your need.
VS Code is lightweight and it has many powerful features. This is the reason why it becoming popular among Python developers. Visual studio code is a code editor that you can use for python development. This is not only mean for python, It supports other languages also.
Download and Install Visual Studio Code in Windows 10
Let’s see how to download and install free visual studio code (VS Code).
First download visual studio code. Based on the operating system, you can download VS Code.
- After downloading, Open the VS Code and then accept the agreement and click on Next.
- Once you will click on Next, a default location will appear. If you don’t want to change the default location then click on Next.
Now click on “create a desktop icon” so that it can be accessed from desktop and then click on Next.
After that, click on the Install button. It will start installing the VS Code.
Finally, installation completes, and by default the Launch Visual Studio Code will appear with check mark. Click on the Finish button, and the visual studio code will get open.
Now you can see Visual Studio Code has been started on windows 10.
Install Python Extension for Visual Studio Code
To install the extension, open up the extension, menu which is present on the left side, and write on the search space “Python”.
Then select the first one that pops up, You can click Install for the respective extension.
Create hello world program in python using Visual Studio Code
Now, we will see how to create hello world program in python in vs code.
Open visual studio code. Then File -> New File.
Then in the file write the below code:
msg = "Hello World" print(msg)
Then Save the file Ctrl+S and then give a file name with .py extension and save type as Python.
The file will looks like below:
To Run the code, Right-click anywhere in the editor window and select Run Python File in Terminal.
The output you can see in the Terminal like below:
You can also, Run the code manually using the command line by simply writing python and Path of the file in the terminal.
You can see below, I have copied the Path of the File after writing python.
python E:\project-python\HelloWorld.py
Now, If you enter then you will see the Output.
We can follow the above steps to create hello world program in python using visual studio code. And how to download and install Visual Studio Code in windows 10, and also we have seen how to install Python Extensions in vs code.
You may like following Python tutorials:
Conclusion
I hope this article helps you to create a hollo world program in Python.
- Create a hello world program in Python
- Python Hello World program using python 3.8 and Pycharm 2020
- Run your Python file from the command prompt
- Create a hello world program in Python using Visual Studio Code
- Visual studio code download and installation
- Install Python Extension for Visual Studio Code
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.
Hello World Programming Tutorial for Python
Estefania Cassingena Navone
🔹 Hello, World!
Hi! if you are reading this article, then you are probably starting to dive into the amazing world of programming and computer science. That’s great.
In this article, you will learn:
- How to write your first «Hello, World!» program in Python.
- How to save your code in a Python file.
- How to run your code.
Writing this program when you are starting to learn how to code is a tradition in the developer community.
Enjoy this moment because it will definitely be part of your memories in the coming months and years when you remember your first steps.
🔸 «Hello, World!» in the Python Shell
Step 1: Start IDLE
During this article, we will work with IDLE (Python’s Integrated Development and Learning Environment), which is automatically installed when you install Python. This is where you will write and run your Python code.
The first thing that you need to do is to open IDLE. You will immediately see the screen shown below.
This is called the Python shell (interactive interpreter). It is an interactive window where you can enter lines or blocks of code and run them immediately to see their effect and output.
💡 Tip: By default, you will see a smaller font size. You can customize this in «Options > Configure IDLE».
Step 2: Display the Message
You need to tell the program that you want to display a specific message by writing the appropriate line of code.
In Python, we use print() to do this:
- First, we write print .
- Then, within parentheses, we write the message or value that we want to display.
💡 Tip: The message «Hello, World!» is surrounded by double quotation marks because it is represented as a string , a data type that is used to represent sequences of characters in your code (for example, text).
Step 3: See the Output
You will see the following output if you write this line of code in the Python shell and press enter:
💡 Tip: You will notice that the color of the message inside print() changes to green when you add the last quotation mark.
This occurs because IDLE assigns different colors to the different types of elements that you can write in your code (notice that print is displayed in purple). This is called «syntax highlighting».
Great! You just wrote your first «Hello, World!» program in Python.
If you want to save it in order to run it later (or just to keep it as a nice memory of your first Python program!), you will need to create a Python file, so let’s see how you can do that.
🔹 «Hello, World!» in a Python File
Step 1: Create a File
To create a Python file in IDLE, you need to:
💡 Tips: You can also use the keyboard shortcut Ctrl + N .
After you click on New File , you will immediately see a new file where you can write your code:
Step 2: Write the Code
In the new file, write this line of code to print «Hello, World!» :
💡 Tip: The thick vertical black line shows where the cursor is currently at.
Step 3: Save the File
Save the new file by clicking on File > Save or by using the keyboard shortcut Ctrl + S . You will need to write a name for your file and choose where you want to save it.
After saving the file, you will see something very similar to this in the folder that you selected:
💡 Tips: By default, line numbers will not be displayed in the file. If you would like to display them (like in the images above) go to Options > Configure IDLE > General > Check the «Show line numbers in new windows» box.
Step 4: Run the Program
Now you can run your file by clicking on Run > Run Module:
A new window will be opened and you should see the output of your program in blue:
Now your program is safely stored in a Python file and you can run it whenever you need to.
🔸 Customize Your Program
You can customize your program to make it unique. You just need to edit the Python file and change the string.
For example, you can add your name after Hello, World! :
If you run the file, you will see the string displayed in the Python shell:
🔹 First Python Program Completed
Awesome work. You just wrote your first Python program.
Programming and Computer Science will be key for the future of humanity. By learning how to code, you can shape that future.
You’ll create amazing new products and platforms, and help take us one step further towards a world where technology will be part of every single aspect of our daily lives.
To learn more about the coding uses of Python, you might like to read my article «What is Python Used For? 10+ Coding Uses for the Python Programming Language»
I really hope that you liked my article and found it helpful. Follow me on Twitter @EstefaniaCassN and check out my online courses. ⭐️