Your First Python Program

Welcome to the exciting world of Python programming! If you’re reading this, you’re probably eager to write your first Python program. Don’t worry, we’ve got you covered. In this tutorial, we’ll guide you through the process of writing and running your first Python program. Let’s get started!

Set Up Your Environment

Before you start coding, you need to set up your Python environment. If you haven’t installed Python yet, you can download it from the official Python website. You can also use an Integrated Development Environment (IDE) like Thonny, which comes with Python bundled in it. Once you’ve installed Python, you’re ready to start coding!

Write Your First Python Program

Now that we have Python up and running, we can write our first Python program. We’ll start with the classic “Hello, World!” program. This is a simple program that prints the text “Hello, World!” to the console.

Here’s what the code looks like:

print("Hello, World!")
Python

Understanding Your First Python Program

Let’s take a moment to understand what’s happening in our “Hello, World!” program. The print function is a built-in Python function that prints the specified message to the screen. The message can be a string, or any other object, the object will be converted into a string before written to the screen. In our program, the message is the string “Hello, World!”.

Run Your First Python Program Online: Easiest Way

Online Code Editor of SkillSeminary.com
  • Select Language Python
  • Copy and paste above code
Online Code Editor of SkillSeminary.com: Select Language and paste the code
  • Click “Run the Code”.
Online Code Editor of SkillSeminary.com: Run the hello world code and see output

Run Your First Python Program in Your Computer

You can type this code into any text editor or IDE and save it as hello_world.py. The .py extension indicates that this is a Python file.

Example on Windows with Notepad, installed python and Command Prompt or PowerShell

You can use just Window’s notepad to create your first code:

  • On Windows, click “Start” menu and search “Notepad”. After opening the file, please paste above code.
python code in notepad
  • Save the file as “hello.py”. Make sure to set “Save as type:” as “All files” as below:
Saving python code in notepad

Using Command Prompt to Run Python code

Here are the detailed steps:

  • Open Command Prompt. For that, you can click “Start” and search for “cmd”.
  • Use the command “cd <your folder where you have put hello.py> to go the directory where you have put your python file hello.py. In following example, we have used the command to go the folder where we have put hello.py.
cd C:\Users\shish\OneDrive\Documents\Python_Practice
Python code run on Windows with Command Prompt
  • Then run the python file using the following command.
python hello.py
  • You will see the desire output as shown in the above figure.

Using Windows PowerShell to Run Python Code

Alternatively, you can use PowerShell as well. See below.

Python code run on Windows with Powershell

Run Your First Program on Jupyter Notebook

Using Jupyter Notebook is a more common way to run Python code. See the next tutorial article to know how to do that.

Let’s take a moment to understand what’s happening in our “Hello, World!” program. The print function is a built-in Python function that prints the specified message to the screen. The message can be a string, or any other object, the object will be converted into a string before written to the screen. In our program, the message is the string “Hello, World!”.

Expanding Your First Python Program

Now that you’ve written your first Python program, you can start to expand on it. For example, you could modify the program to print a different message, or to print multiple messages. Here’s an example:

print("Hello, World!")
print("Welcome to Python programming!")
Python

When you run this program, it will print two lines of text to the console:

Hello, World!
Welcome to Python programming!
Python

As you can see, Python makes it easy to print messages to the console. But Python is capable of much more than just printing messages. As you continue to learn Python, you’ll discover that it’s a powerful language that can be used for a wide range of tasks.

Scroll to Top