First Python Program
Welcome to your first Python programming course! In this beginner-friendly course, we’ll take you through the exciting journey of writing your very first Python program. Don’t worry if you’ve never written a single line of code before; we’ll start from the very basics and gradually build up your programming skills.
We’ll start by writing the simplest and most famous program in the world of programming: “Hello, World!“. This program will introduce you to the basic syntax of Python and get you comfortable with running code.
Writing your First Python Program:
Open a text editor (like Notepad on Windows or Text Edit on Mac) and type the following line of code:
print("Hello, World!")
Understanding the Code:
print()
is a function in Python. It’s used to display messages on the screen."Hello, World!"
is a string of characters enclosed within double quotes. Whatever is inside the quotes will be printed to the screen.
Running your Program:
After typing the code, save the file with a .py
extension. For example, you could save it as hello.py
. Now, open your command line interface (like Command Prompt on Windows or Terminal on Mac) and navigate to the directory where you saved your Python file.
Once you’re in the correct directory, type the following command and press Enter:
python hello.py
You should see the output:
Hello, World!
Congratulations! You’ve just written and executed your first Python program.
Explanation:
Imagine your computer is like a robot that can do all sorts of amazing things. But, just like with any robot, you have to give it instructions in a language it understands. Python is one of those languages.
In our first program, we’re telling the computer to say “Hello, World!” to us. We do this by using the word print
, which tells the computer to show something on the screen. Then, we put what we want the computer to say inside two special characters called quotation marks.
When you run the program, the computer reads your instructions and does exactly what you told it to do – it prints out “Hello, World!” for you to see.
In this lesson, you learned how to write, understand, and run your first Python program. This is just the beginning of your journey into the exciting world of programming! Stay tuned for more lessons where we’ll explore new concepts and build on what you’ve learned. Keep practicing, and soon you’ll be creating amazing things with code!