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:
When you run this line of code, Python will output:
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:
3. Save the file with a .py extension, for example, hello_world.py.
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:
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.
In this code:
defis a keyword that tells Python we are defining a function.print_hello_worldis the name of our function.nameinside the parentheses is a parameter—a variable that the function can receive as input.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:
- Start with the basics: Learn the basic syntax and structure of Python. Understand variables, data types, and simple operations.
- Practice coding: The best way to learn programming is by doing. Write small programs, experiment with different functions, and try to solve simple problems.
- Use online resources: There are numerous free and paid resources available online. Check out DataCamp’s Python curriculum for more!
- Read Python documentation: Familiarize yourself with the official Python documentation. It’s a comprehensive resource for understanding Python's capabilities and features.
- 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.
- 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.
- 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!

Adel is a Data Science educator, speaker, and VP of Media at DataCamp. Adel 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.
FAQs
How do you print "Hello World!" in Python?
Call the print() function with text in quotes, like print("Hello World!"). Running that single line outputs Hello World! to the console, and it's the traditional first exercise for learning a new language's basic syntax and structure before moving on to variables and functions.
Do you need to install Python to try Hello World?
No. DataCamp DataLab runs Python directly in the browser, so Hello World works with no installation. For a permanent setup, official installation guides cover both MacOS and Windows, letting you install Python locally and run scripts from the command line afterward.
How do you run a Python script from the command line?
Save the code in a text file with a .py extension, such as hello_world.py. Open the command line or terminal, use cd to navigate to that folder, then run python hello_world.py to execute the script and print the output, confirming it ran outside of an IDE.
How do you write a Python function that prints a personalized greeting?
Define the function with def, give it a name parameter, then call print() inside it, for example def print_hello_world(name): print("Hello", name, "!"). Calling print_hello_world("Alice") outputs Hello Alice !, showing how functions reuse code with different inputs instead of writing separate print statements for each person.
What should you learn after writing your first Python program?
After Hello World, focus on variables, data types, and basic operations, then practice writing small programs and building projects like a calculator or web scraper. DataCamp's Python curriculum, courses like Writing Functions in Python, and the official Python documentation all help build skills further.



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: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.