In this tutorial, you'll learn how to create your first Python program: the classic "Hello, World!" example. This is your first step into the world of programming.
"If you can write 'hello world', you can change the world." — Raghu Venkatesh
Creating a New Python Project
Steps:
-
Create a Directory:
-
Create a folder named
helloworld
anywhere on your computer (e.g.,C:\helloworld
or~/helloworld
).
-
-
Open in VS Code:
-
Launch Visual Studio Code.
-
Open the
helloworld
directory.
-
-
Create a Python File:
-
Create a new file named
app.py
. -
Enter the following code and save it:
-
print('Hello, World!')
The print()
function is a built-in Python function that displays a message on the screen.
What is a Function?
A function is a reusable piece of code that takes inputs, applies some logic, and returns an output.
Examples:
-
Sum of two numbers
-
Multiplication of two numbers
In our example, print()
is a function:
-
It accepts a string as input.
-
It outputs the string to the screen.
Python offers many built-in functions, and you can also create your own.
Executing the Python Hello World Program
Run from Command Line:
-
Open Terminal or Command Prompt
-
Navigate to the
helloworld
directory:
cd path/to/helloworld
-
Execute the Python file:
-
On Windows:
python app.py
-
On macOS/Linux:
python3 app.py
If everything is correct, you should see:
Hello, World!
Run Inside VS Code:
-
Open the menu: Terminal > New Terminal
-
Shortcut: `Ctrl+Shift+`` (backtick key, usually under the Esc key)
-
Then run:
python app.py
Using Python IDLE
Python comes with a simple editor called IDLE (Integrated Development and Learning Environment).
Features of IDLE:
-
Syntax highlighting
-
Smart indentation
-
Auto-completion
How to Use IDLE:
-
Launch IDLE (find it in your installed apps).
-
A Python Shell window will open.
-
After the
>>>
prompt, type:
print('Hello, World!')
-
Press Enter and you'll immediately see the output.
IDLE is great for quick experiments and learning.
Summary
-
Create a Python file and use
print()
to display messages. -
Execute Python scripts via Command Line, Terminal, or directly inside VS Code.
-
Use Python IDLE for quick testing and learning.
Congratulations! You've just written and run your first Python program!
Copyright Statement: Unless stated otherwise, all articles are original to this site, please credit the source when sharing.
Article link:http://pybeginners.com/python-tutorial/python-hello-world/
License Agreement:Attribution-NonCommercial 4.0 International License