Skip to main content

Python Hello World: A Beginner’s Guide to Programming

Learn the fundamentals of Python by running the print(“Hello World”) program.
Jun 2024  · 3 min read

Welcome to the world of Python programming! If you're new to coding, you're in the right place. This article will guide you through writing your first Python program: printing "Hello World!" This simple exercise is a rite of passage for beginners and a great way to get acquainted with Python.

We'll also explore creating a function to expand your understanding further. By the end of this article, you'll have a solid understanding of how to begin your Python journey.

The Short Answer: How to Print “Hello World!”

To print “Hello World!”, use the print() function as illustrated below:

print("Hello World!")
Hello World!

The Prerequisites: Installing Python

Before we dive into coding, we need to ensure Python is installed on your computer. Python is a versatile and powerful language, and in the section below, there are a couple of resources you can leverage to install it on your computer.

For detailed installation instructions, refer to our comprehensive guide for MacOS and Windows. Alternatively, if you prefer not to install anything just yet, you can start coding immediately using DataCamp DataLab, a browser-based Integrated Development Environment (IDE), which lets you code right in the browser, with no installations needed.


Skip the installation process and experiment with data science code in your browser with DataLab, DataCamp's AI-powered notebook.

Get Started

Running Your First Python Program: Print “Hello World!”

The first step in learning any programming language is often to print "Hello World!" This tradition helps you understand the language's basic syntax and structure. In Python, this is done using the print() function.

Using the print() function

The print() function is one of the most frequently used functions in Python. It outputs text. Let's see it in action:

print("Hello World!")

When you run this line of code, Python will output:

Hello World!

Running Your First Python Program: Print “Hello World!”

While running Python code in an IDE is convenient, you can also create a script file and run it. This is useful for saving and running larger programs. Here’s how you can do it:

1. Open a text editor (like Notepad on Windows or TextEdit on MacOS).

2. Type the following code:

print("Hello World!")

3. Save the file with a .py extension, for example,

4. Open your command line interface (CLI) or terminal. On Windows computers, press the Windows key, type "Command Prompt," and hit Enter. This will open the Command Prompt (CLI). For macOS, press Command + Space, type "Terminal," and hit Enter. This will open the Terminal application.

5. In the command line, use the cd command (short for "change directory") to navigate to the folder where you saved your file. For example, if you saved your file on the Desktop, you would type:

cd Desktop

6. Run the script by typing:


Congratulations! You've just run your first Python script.

Bonus: Creating a Function that Prints “Hello World!”

One of the beauties of Python, and programming in general, is the ability to create systems that automate tasks. Functions are the building blocks of these systems in Python. A function is a reusable block of code that performs a specific task.

Let's create a function that takes a person's name as an argument and prints a personalized greeting.

def print_hello_world(name):
    print("Hello", name, "!")

# Calling the function
Hello Alice !

In this code:

  1. def is a keyword that tells Python we are defining a function.
  2. print_hello_world is the name of our function.
  3. name inside the parentheses is a parameter—a variable that the function can receive as input.
  4. print(“Hello”, name, “!”) is the function's action. Here, we use commas to separate between the different elements of the print statement.

For more on functions, check out this interactive course on Writing Functions in Python from scratch, where you’ll build Python functions right in the browser!

How to Learn Python

Learning Python is an exciting journey that opens up many possibilities in the programming world. Here are some steps and resources to help you get started:

  1. Start with the basics: Learn the basic syntax and structure of Python. Understand variables, data types, and simple operations.
  2. Practice coding: The best way to learn programming is by doing. Write small programs, experiment with different functions, and try to solve simple problems.
  3. Use online resources: There are numerous free and paid resources available online. Check out DataCamp’s Python curriculum for more!
  4. Read Python documentation: Familiarize yourself with the official Python documentation. It’s a comprehensive resource for understanding Python's capabilities and features.
  5. Join a community: Engage with other learners and experienced developers. Communities like Stack Overflow, Reddit’s r/learnpython, and Python Discord servers are great places to ask questions, share knowledge, and get support.
  6. Build projects: Apply what you've learned by working on small projects. This could be anything from a simple calculator to a web scraper. Projects help solidify your knowledge and provide practical experience.
  7. Explore advanced topics: Once you're comfortable with the basics, explore more advanced topics like object-oriented programming, web development with frameworks like Django or Flask, and data analysis with libraries like Pandas and NumPy.

For more detailed guidance, read our comprehensive guide on how to learn Python from scratch.

Get Started with Python

Now that you've written your first Python program and created a function, you’ve taken the first step to mastering this powerful language. Keep experimenting with Python, try out new ideas, and don't hesitate to explore more advanced topics as you grow more comfortable.

Start your Python learning journey today, and happy coding!

Learn Python From Scratch

Master Python for data science and gain in-demand skills.

Photo of Adel Nehme
Adel Nehme

Adel is a Data Science educator, speaker, and Evangelist at DataCamp where he has released various courses and live training on data analysis, machine learning, and data engineering. He is passionate about spreading data skills and data literacy throughout organizations and the intersection of technology and society. He has an MSc in Data Science and Business Analytics. In his free time, you can find him hanging out with his cat Louis.


cheat sheet

Python Cheat Sheet for Beginners

Python is the most popular programming language in data science. Use this cheat sheet to jumpstart your Python learning journey.
Richie Cotton's photo

Richie Cotton

8 min


Python Print() Function

Learn how you can leverage the capability of a simple Python Print function in various ways with the help of examples.
Aditya Sharma's photo

Aditya Sharma

10 min


Python Tutorial for Beginners

Get a step-by-step guide on how to install Python and use it for basic data science functions.
Matthew Przybyla's photo

Matthew Przybyla

12 min


Python String format() Tutorial

Learn about string formatting in Python.
DataCamp Team's photo

DataCamp Team

5 min


Python Switch Case Statement: A Beginner's Guide

Explore Python's match-case: a guide on its syntax, applications in data science, ML, and a comparative analysis with traditional switch-case.
Matt Crabtree's photo

Matt Crabtree

5 min


Test-Driven Development in Python: A Beginner's Guide

Dive into test-driven development (TDD) with our comprehensive Python tutorial. Learn how to write robust tests before coding with practical examples.
Amina Edmunds's photo

Amina Edmunds

7 min

See MoreSee More