Your first Python script: Hello World!

Oscar Holt
3 min readJun 23, 2024

--

Your first Python script: Hello World!

Python is a versatile and powerful programming language that is widely used in various fields, from web development to data science. If you are new to programming or just starting with Python, writing your first script can be an exciting and rewarding experience. In this article, we will guide you through the process of creating your first Python script: the classic “Hello, World!” program.

Why Python?

Before we dive into the code, let’s briefly discuss why Python is a great choice for beginners:

  1. Readability: Python’s syntax is clear and easy to understand, making it an excellent language for beginners.
  2. Versatility: Python can be used for web development, data analysis, artificial intelligence, scientific computing, and more.
  3. Community Support: Python has a large and active community, which means you can find plenty of resources, tutorials, and libraries to help you along the way.

Setting Up Your Environment

To write and run Python scripts, you need to have Python installed on your computer. Follow these steps to set up your environment:

  1. Download Python: Visit the official Python website and download the latest version of Python for your operating system.
  2. Install Python: Run the installer and follow the instructions. Make sure to check the option to add Python to your system’s PATH during installation.
  3. Verify Installation: Open a terminal or command prompt and type python — version to verify that Python is installed correctly. You should see the version number of Python that you installed.

Writing Your First Script

Now that you have Python installed, let’s write your first script. Follow these steps:

  1. Open a Text Editor: You can use any text editor to write your Python script. Some popular choices include Visual Studio Code, Sublime Text, and even the built-in Notepad on Windows or TextEdit on macOS.
  2. Create a New File: Open your text editor and create a new file. Save it with a .py extension, for example, hello_world.py.
  3. Write the Code: In your new file, type the following code:

print(“Hello, World!”)

4. Save the File: Save your file after writing the code.

Running Your Script

To run your Python script, follow these steps:

  1. Open a Terminal or Command Prompt: Navigate to the directory where you saved your hello_world.py file.
  2. Run the Script: Type the following command and press Enter:

python hello_world.py

3. See the Output: You should see the text `Hello, World!` printed in your terminal or command prompt.

Understanding the Code

Let’s break down the code you just wrote:

  • print(“Hello, World!”): This line uses the print function to display the text “Hello, World!” on the screen. The print function is a built-in function in Python that outputs text to the console.

Conclusion

Congratulations! You have just written and executed your first Python script. While it may seem simple, this “Hello, World!” program is an important milestone in your programming journey. From here, you can explore more complex concepts and start building your own projects.

Python’s simplicity and readability make it an ideal language for beginners, and with a strong community and extensive resources, you’ll have plenty of support as you continue to learn. Happy coding!

--

--

Oscar Holt

🚀 Programmer | 🔧 Lifelong Learner and Knowledge Sharer | 🧩 Problem Solver and Optimizer