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.
- Readable syntax. Python code looks close to English, so you spend less time decoding symbols.
- Short setup. You can install Python and run your first program in under ten minutes.
- Wide use. Python is used in web development, data analysis, automation, machine learning, and testing.
- Strong community. When you get stuck, someone has already asked your question online.
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
- Go to the official Python website and download the latest stable version.
- Run the installer.
- 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
pythoncommand. - Click Install Now and wait for the process to finish.
- 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:
- IDLE comes bundled with Python. It is fine for your first few programs.
- VS Code is free, popular, and works well as you grow. Install the Python extension after installing VS Code.
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.pyYou should see the message printed on screen.
What Just Happened?
Let us break down the line.
printis a built-in function. It displays output on the screen.- Parentheses
()hold the value you want to print. - Quotes
" "tell Python that the content inside is text, also called a string. - The period at the end marks the end of the statement. Unlike Java or C, Python does not require a semicolon.
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
name = "Rahul"stores a string.age = 22stores an integer.height = 5.8stores a float (a number with a decimal point).is_student = Truestores a boolean.
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
- Names can contain letters, numbers, and underscores.
- Names cannot start with a number.
- Names are case-sensitive, so
ageandAgeare different. - Use descriptive names.
total_priceis better thantp.
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
input("What is your name? ")shows the message and waits for the user to type something.- Whatever the user types is stored in the variable
name. - The
+operator joins strings together. This is called string concatenation.
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
int(...)converts the text input into an integer.- If you typed
10and20, Python stores them as numbers, not text. - Without
int(), the+operator would join them as strings, giving"1020"instead of30.
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
- The
ifstatement checks a condition. - The lines inside
ifandelseare indented with four spaces. - If you remove that indentation, Python raises an
IndentationError.
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
- Lines starting with
#are single-line comments. - They help you and others understand your logic later.
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
float(input(...))allows decimal prices.subtotal * tax_ratecalculates tax.:.2finside the f-string rounds the number to two decimal places, which is how currency is usually displayed.
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.
- Automation scripts use
input, variables, andprintto gather data and log results. - Data analysis relies on the same data types and type conversion when cleaning CSV files.
- Web applications read user input from forms and convert it to the right type before saving it to a database.
- Testing tools compare expected and actual output using the same
ifconditions you just wrote.
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.
- Forgetting the
int()orfloat()conversion. Input is always a string. Doing math without converting gives unexpected results. - Mixing up
=and==. A single=assigns a value. A double==compares two values. Using=in anifcondition causes an error. - Wrong indentation. Python relies on indentation to define blocks. Missing or inconsistent spaces cause
IndentationError. - Not adding Python to PATH on Windows. This makes the
pythoncommand unrecognisable in the terminal. - Using the wrong version. If
pythondoes not work, trypython3. The difference matters on macOS and Linux. - Naming files after standard modules. A file named
random.pycan shadow Python's built-inrandommodule and cause confusing import errors. - 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.
- 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
- Write short programs often. Ten small programs teach more than one long one.
- Use meaningful variable names. Future you will thank present you.
- Read error messages carefully. Start from the last line.
- Keep files organised. Create one folder for practice scripts.
- Run your code after every small change. Catching errors early is easier.
- Use f-strings for formatting. They are clean and modern.
- Save and back up your work. Use Git when you are ready for the next step.
Interview Tips for Python Beginners
Even at entry level, interviewers check whether your fundamentals are solid.
- Tip 1: Explain
printvsinput. Print displays output. Input reads user data and always returns a string. - Tip 2: Know the basic data types. Be ready to explain
int,float,str, andboolwith examples. - Tip 3: Explain why Python needs indentation. It defines code blocks. Other languages use braces.
- Tip 4: Know how to convert types.
int("5")gives the number 5.str(5)gives the text "5". - Tip 5: Be honest about what you do not know. Interviewers respect candidates who say "I have not used that yet, but here is how I would find out."
- Tip 6: Practise writing code on paper or a whiteboard. Many interviews ask you to write a small function without an editor.
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 →
