Step 1: Installing Python
Let's start from the very beginning — getting Python on your computer.
How to Download & Install Python
Step 1: Go to the official website — python.org
Step 2: Click on the Downloads button. It will automatically detect your operating system (Windows/Mac/Linux) and suggest the latest version.
Step 3: Download Python 3.13.x (whatever the latest 3.13 version is shown)
Step 4: Run the installer
IMPORTANT — Windows Users (Read This Carefully)
When the installer opens, you will see a checkbox at the bottom that says:
☐ Add Python to PATH
CHECK THIS BOX BEFORE CLICKING INSTALL.
This is the most common beginner mistake. If you skip this, Python won't work from your terminal/command prompt.
After checking that box, click "Install Now" and wait for it to finish.
Verify Installation
After installing, let's confirm Python is working correctly.
On Windows:
- Press
Windows + R, typecmd, press Enter - A black window (Command Prompt) will open
- Type this and press Enter:
python --version
On Mac/Linux:
- Open Terminal
- Type:
python3 --version
You should see something like:
Python 3.13.1
If you see this — Python is successfully installed! 🎉
If you see an error like "python is not recognized" — it means you forgot to check the PATH checkbox. In that case, uninstall Python and install again, this time checking that box.
Installing VS Code (Code Editor)
Python is installed. Now you need a place to write your code. We'll use VS Code — it's free and the most popular editor.
Step 1: Go to code.visualstudio.com
Step 2: Download for your OS and install it (simple next-next-finish installation)
Step 3: Open VS Code
Step 4: On the left side, click the Extensions icon (looks like 4 squares)
Step 5: Search for "Python" — install the one made by Microsoft (it has millions of downloads)
This extension helps VS Code understand Python code — gives you suggestions, highlights errors, etc.
Setting Up Your First Project Folder
Good habit from day one — keep your code organized.
Step 1: Create a folder on your Desktop or anywhere you like. Name it something like python-learning
Step 2: Open VS Code → File → Open Folder → select your python-learning folder
Step 3: Inside VS Code, create a new file → name it hello.py
The .py extension tells your computer "this is a Python file"
Step 2: Your First Python Program
The Tradition — "Hello, World!"
In programming, when you learn any new language, the very first program everyone writes is called "Hello, World!". It's a tradition since the 1970s. So let's follow it!
Writing Your First Program
Open the hello.py file you created in VS Code and type this:
print("Hello, World!")
That's it. This is a complete, valid Python program.
Running Your Program
Method 1 — Using VS Code Terminal:
In VS Code, go to Terminal → New Terminal (or press Ctrl + backtick)
A terminal will open at the bottom of VS Code. Type:
python hello.py
On Mac/Linux:
python3 hello.py
Press Enter. You will see:
Hello, World!
Method 2 — Using the Play Button:
In VS Code, you'll see a ▶ Play button on the top right corner. Just click it and it runs your file directly.
What is print()?
print() is a function that displays text on the screen.
Whatever you write inside the brackets () with quotes, it will show on screen.
Let's try a few more examples. Update your file:
print("Hello, World!") print("My name is Gagan") print("I am learning Python") print("This is my first program!")
Run it. Output:
Hello, World!
My name is Gagan
I am learning Python
This is my first program!
Each print() starts on a new line automatically.
Quotes — Single or Double?
Both work in Python. These two lines do the exact same thing:
print("Hello, World!") print('Hello, World!')
You can use single quotes ' ' or double quotes " " — your choice. Just be consistent. Most people use double quotes.
What Happens If You Make a Mistake?
Let's intentionally break the code so you understand errors:
print("Hello, World!"
Run this. You'll see:
SyntaxError: '(' was never closed
This is called a Syntax Error — it means your code has a typo or something is missing. Here the closing bracket ) is missing.
Fix it back:
print("Hello, World!")
Important mindset: Errors are normal. Every programmer gets errors daily. Don't panic when you see one — just read it carefully and it usually tells you what went wrong.
Comments — Notes in Your Code
Sometimes you want to write notes in your code that Python should ignore. These are called comments.
Use the # symbol:
# This is my first Python program print("Hello, World!") # This prints a message
# Python will ignore everything after the # symbol # print("This line will NOT run") print("But this line will run")
Output:
Hello, World!
But this line will run
Comments are very useful for:
- Explaining what your code does
- Temporarily disabling a line without deleting it
- Leaving notes for yourself or others
Your First Exercise 🏋️
Write a program that prints the following output exactly:
Welcome to Python!
My name is [your name]
I am a beginner
Let's learn together!
Use 4 separate print() statements. Try it yourself first, then move to the next step.
No comments:
Post a Comment