What Is Python Program ?
A Python program is a sequence of text instructions written in the Python programming language that a computer executes to perform a specific task. Python is highly popular because it uses clean, simple English-like words, making it incredibly easy for humans to read and write.
How a Python Program Works ?
1. Writing Code : You write your instructions in a plain text file and save it
with a .py extension (for example: main.py).
2. Translation : Computers cannot read Python directly. When you run the
program, a software called the Python Interpreter reads your code line by line.
3. Execution : The interpreter translates those English-like commands into
machine code (0s and 1s) on the fly, and your computer executes the task.
First Python Program
print("Hello, World!")
Hello, World!
How does this code work ?
print(): This is a built-in function of Python. Its job is to display the text typed in
it as output on the computer screen.
Double Quotes ("..."): Python treats anything written inside quotes as a string, i.e.,
plain text, and prints it as is on the screen.
Method A: Using IDLE or VS Code (by creating a file)
1. Open your code editor (such as Notepad, VS Code, or IDLE).
2. Type the line above: print("Hello, World!")
3. Save this file as hello.py (remember, Python file extensions should always be .py).
4. Go to your terminal or command prompt (CMD) and go to the folder containing this file and
type this command: python hello.py
5. The output will appear on the screen: Hello, World!
Method B: Using Interactive Mode (without creating a file)
1. Open your computer's Terminal (Mac/Linux) or Command Prompt (Windows).
2. Simply type python and press Enter. This will open the Python interactive shell (where >>>
appears).
3. Now simply type: print("Hello, World!") and press Enter. You will immediately get the output
below.