Beginner Guide · 12 min read

Python Tutorial for Beginners: Your First Program Step by Step

Starting with Python feels exciting and a little confusing at the same time. You have heard it is beginner-friendly, but the moment you open a code editor, questions pile up: Where do I type the code? How do I run it? What does that error mean?

This Python tutorial for beginners answers those questions in order. By the end, you will have installed Python, written your first program, understood what each line does, and avoided the mistakes that slow most beginners down.

Why Python Is a Great First Language

Python is one of the most recommended languages for people learning to code for the first time. The reasons are practical.

If you are serious about learning, a structured Python course helps you move from random tutorials to a clear path. But before that, let us write your first line of code.

Step 1: Install Python on Your Computer

You cannot run Python programs without the Python interpreter. The interpreter is the program that reads your code and executes it.

Installing on Windows

  1. Go to the official Python website and download the latest stable version.
  2. Run the installer.
  3. Important: Tick the checkbox that says "Add Python to PATH" at the bottom of the first screen. If you skip this, your command line will not recognise the python command.
  4. Click Install Now and wait for the process to finish.
  5. Open Command Prompt and type python --version. If you see a version number, the installation worked.

Installing on macOS or Linux

Most macOS and Linux systems come with Python pre-installed. Open Terminal and type python3 --version to check. If it is missing, install it through your package manager or the official installer.

Choosing an Editor

You have two simple options:

Do not spend hours choosing an editor. Pick one and start writing code.

Step 2: Write Your First Python Program

Open your editor, create a new file called hello.py, and type this single line.

print("Hello, World! I am learning Python.")

Save the file. Now open your terminal, navigate to the folder where you saved it, and run:

python hello.py

You should see the message printed on screen.

What Just Happened?

Let us break down the line.

That is your first program. Simple, and it works.

Step 3: Understand Python Variables

A variable is a named container that stores a value. You create one by assigning a value to a name.

name = "Rahul"
age = 22
height = 5.8
is_student = True

print(name)
print(age)
print(height)
print(is_student)

Explanation

Notice that you did not declare the type. Python figures it out automatically. This is called dynamic typing, and it is one reason Python feels easier for beginners.

Rules for Naming Variables

Step 4: Take Input from the User

Programs become useful when they interact with people. The input() function reads text typed by the user.

name = input("What is your name? ")
print("Hello, " + name + "! Welcome to Python.")

Explanation

Here is a cleaner way to do the same thing using an f-string, which is the modern Python style.

name = input("What is your name? ")
print(f"Hello, {name}! Welcome to Python.")

The f before the quotes means you can put variables directly inside curly braces {}. Most Python developers prefer this approach because it is readable.

Step 5: Work with Numbers

Let us do a small calculation. The input() function always returns text, so you must convert it to a number before doing math.

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

total = num1 + num2
print(f"The sum is {total}")

Explanation

This is one of the most common beginner mistakes, so remember it.

Step 6: Understand Indentation in Python

Indentation means adding spaces at the start of a line. In many languages, indentation is optional formatting. In Python, it is part of the syntax.

age = 18

if age >= 18:
    print("You can vote.")
else:
    print("You are too young to vote.")

Explanation

Use spaces, not tabs, and stick to four spaces consistently. This small habit prevents hours of confusion.

Step 7: Add Comments to Your Code

Comments explain what your code does. Python ignores them when running the program.

# This program calculates the area of a rectangle

length = 10      # length in centimetres
width = 5        # width in centimetres

area = length * width
print(f"Area: {area} square cm")

Explanation

Do not over-comment. Explain the "why", not the obvious "what". A comment saying # add 1 to x above x = x + 1 adds no value.

Step 8: A Small Real-World Practice Program

Here is a program that brings together everything you have learned. It calculates a simple bill with tax.

item_price = float(input("Enter item price: "))
quantity = int(input("Enter quantity: "))
tax_rate = 0.18  # 18% GST

subtotal = item_price * quantity
tax = subtotal * tax_rate
total = subtotal + tax

print(f"Subtotal: {subtotal:.2f}")
print(f"Tax: {tax:.2f}")
print(f"Total: {total:.2f}")

Explanation

Run this with different values. Try ₹100 with a quantity of 3 and see what happens. Change the tax rate and observe the difference. Experimenting like this builds understanding faster than reading alone.

Real-World Use Cases for These Basics

You might think these examples are too simple to matter. They are not. The same building blocks power real applications.

Everything advanced in Python is built on these first steps.

Common Mistakes Beginners Make in Python

These mistakes appear so often that fixing them early saves weeks of frustration.

  1. Forgetting the int() or float() conversion. Input is always a string. Doing math without converting gives unexpected results.
  2. Mixing up = and ==. A single = assigns a value. A double == compares two values. Using = in an if condition causes an error.
  3. Wrong indentation. Python relies on indentation to define blocks. Missing or inconsistent spaces cause IndentationError.
  4. Not adding Python to PATH on Windows. This makes the python command unrecognisable in the terminal.
  5. Using the wrong version. If python does not work, try python3. The difference matters on macOS and Linux.
  6. Naming files after standard modules. A file named random.py can shadow Python's built-in random module and cause confusing import errors.
  7. Ignoring error messages. Beginners often skip the last line of the error message. That line usually tells you exactly what went wrong and on which line.
  8. Copying code without running it. Typing code yourself and fixing your own typos builds far stronger skills than copy-paste.

Best Practices to Start Right

Interview Tips for Python Beginners

Even at entry level, interviewers check whether your fundamentals are solid.

Frequently Asked Questions

How do I start Python for beginners?

Install Python from the official website, choose an editor like VS Code or IDLE, and write your first print statement. Then practise small programs daily.

What is the first program to write in Python?

The traditional first program is print("Hello, World!"). It confirms that Python is installed and your editor works.

How do I install Python on Windows?

Download the installer from the official site, tick "Add Python to PATH", and click Install Now. Then verify with python --version in Command Prompt.

What is the difference between print and input in Python?

print displays output on the screen. input reads text typed by the user and returns it as a string.

Is Python easy for beginners?

Yes. Its syntax is close to English, it needs less setup than most languages, and it has a large learning community.

What are variables in Python?

A variable is a name that stores a value, such as age = 22. Python determines the type automatically.

Why is indentation important in Python?

Indentation defines blocks of code. Unlike other languages, Python uses spaces instead of braces to know which lines belong together.

How do I run a Python program?

Save your code in a .py file and run python filename.py in the terminal. You can also run it directly inside your editor.

What are the basic data types in Python?

The most common are int for whole numbers, float for decimals, str for text, and bool for True or False.

What are common mistakes beginners make in Python?

Forgetting type conversion, wrong indentation, using = instead of ==, and ignoring error messages are the most common.

Conclusion

Your first Python program is more than a line of text on a screen. It proves that your environment works, that you can run code, and that you understand the building blocks: variables, input, output, data types, conditions, and indentation.

This Python tutorial for beginners walked through the same steps a structured classroom session would follow. Install Python, write a print statement, take input, do arithmetic, and add comments. Then practise with a small bill calculator and try variations. The more you type and run, the faster the basics become natural.

From here, the logical next steps are data structures like lists and dictionaries, loops, and functions. Each one builds on what you have just learned.

Ready to Go from First Program to Job-Ready?

If you want a structured path from your first program to job-ready Python skills, explore the Python course at our Viman Nagar, Pune institute. You will work through fundamentals, data structures, object-oriented programming, file handling, and real projects with mentor guidance — plus certification and 100% placement assistance.

Continue learning: Browse all free Python guides →