First Python Program
After installing Python, the next step is to write and execute a simple Python program. Python programs are easy to write because they require very little syntax.
Writing Your First Python Program
The simplest Python program prints a message on the screen using the
print() function.
print("Hello, World!")
Output
Hello, World!
How the Program Works
print()is a built-in Python function.- The text inside quotation marks is called a string.
- The
print()function displays the string on the screen.
Running the Program
Save the program with the .py extension, for example:
first_program.py
Open Command Prompt or Terminal in the folder containing the file and run:
python first_program.py
The output will be:
Hello, World!
Another Simple Example
Python can also perform calculations directly:
a = 10
b = 20
sum = a + b
print("Sum =", sum)
Output:
Sum = 30
Key Point:
A Python program can contain variables, expressions, functions
and statements. Python executes the program from top to bottom.