Your first python program

Python is a fantastic programming language for beginners and professionals alike. Writing your first Python program is an exciting milestone!

In this article, we will guide you through the process of writing your very first Python program!

Getting Started

Before we can write our first Python program, ensure that Python is installed on your computer. If not, refer to the tutorial on how to install Python.

Writing Your First Program

Follow these simple steps to write and execute your first Python program:

  • Open a Text Editor or an IDE: Python programs can be written in a simple text editor (like Notepad) or in an Integrated Development Environment (IDE) like VS Code, PyCharm, or IDLE (which comes pre-installed with Python).

  • Editor Screenshot
  • Write Your First Program: Open your text editor or IDE and type the following code:

    print("Hello, World!")

    This simple line of code instructs Python to display the text Hello, World! on the screen.

  • Save Your Program: Save the file with a .py extension. For example, hello_world.py. Remember the location where you save it.

  • Run Your Program: Open the command line (or terminal). Navigate to the folder where your Python file is saved using the cd command. Then type:

    python hello_world.py

    You should see the output: Hello, World!

  • Congratulations! You've just written and executed your first Python program!

Understanding the Code

The code

print("Hello, World!")
works as follows:

  • print(): This is a Python function used to display text or other output on the screen.
  • "Hello, World!": This is the text that the print() function outputs. You can replace it with any text you'd like to display.

Next Steps

Now that you've written your first program, you can experiment by modifying the text inside the print() function or trying new Python features!

Happy Coding! Now you could learn about variables!