The "Hello, World!" program is a simple and traditional first program when learning a new programming language. Here's how you can create and run a "Hello, World!" program in Python:
Writing the "Hello, World!" Program
Open a Text Editor: Open your preferred text editor. This can be a simple text editor like Notepad on Windows, TextEdit on macOS, or any code editor like VSCode, Atom, or Sublime Text.
Write the Code: In your text editor, type the following Python code:
print("Hello, World!")
This one-liner prints the string "Hello, World!" to the console.
Save the File: Save the file with a
.py
extension, for example,hello.py
. The.py
extension indicates that it's a Python file.
Running the Program
On the Command Line:
Open a Terminal (Command Prompt on Windows): Open a terminal or command prompt.
Navigate to the Directory: Use the
cd
command to navigate to the directory where yourhello.py
file is located.cd path/to/your/directory
Run the Program: Type the following command and press Enter to run your Python script:
python hello.py
If you are using Python 3, use
python3
instead ofpython
:python3 hello.py
In an Integrated Development Environment (IDE):
Open an IDE: If you are using an IDE like VSCode, PyCharm, or IDLE, open the IDE.
Open the File: Open your
hello.py
file in the IDE.Run the Program: Look for a "Run" or "Execute" button in the IDE, or use a keyboard shortcut (often
F5
). Clicking this will execute your script.
Understanding the Code
print("Hello, World!")
: This line prints the string "Hello, World!" to the console. Theprint()
function is used to display output.
Conclusion
The "Hello, World!" program is a simple introduction to the syntax and structure of a programming language. Running this program ensures that your Python environment is set up correctly, and you're ready to start coding in Python. As you progress, you'll explore more advanced features and functionalities of the language.