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!
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.
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).
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!
The code
print("Hello, World!")
works as follows:print()
function outputs. You can replace it with any text you'd like to display.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!