Python write your first program


Here's a simple guide to writing and running your first program in Python, typically a "Hello, World!" program. This program will output the text "Hello, World!" to the console.

Step 1: Create a Python File

  1. Open your text editor or Integrated Development Environment (IDE), such as Visual Studio Code, PyCharm, or even a simple text editor like Notepad.
  2. Create a new file and name it hello.py.

Step 2: Write the Code

In your hello.py file, write the following code:

print("Hello, World!")

Step 3: Save the File

Make sure to save the file after writing the code.

Step 4: Run the Program

Using the Command Line:

  1. Open a command prompt (Windows) or terminal (macOS/Linux).

  2. Navigate to the directory where you saved your hello.py file. For example:

    cd path\to\your\directory
  3. Run the program by typing:

    python hello.py

    or, if you're using Python 3 specifically, you might need to use:

    python3 hello.py

Using an IDE:

If you are using an IDE like PyCharm or Visual Studio Code, you can typically run the program by clicking a "Run" button or using a shortcut (like Shift + F10 in PyCharm).

Expected Output

When you run the program, you should see the following output in your console:

Hello, World!

Conclusion

Congratulations! You've successfully written and run your first Python program. This foundational step helps you understand how to create and execute Python code, paving the way for more complex programming tasks.