Learn Python from Scratch
Complete Python Basics for Beginners, Freshers & Non-IT Learners
If you are completely new to programming, Python is one of the best languages to start with.
You don't need to be a computer science graduate or an experienced programmer to learn Python. With the right approach, you can start with simple statements and gradually build programs that solve real problems.
In this beginner-friendly guide, we will understand the most important Python basics using simple explanations and real-world examples.
What is Python?
Python is a high-level, general-purpose programming language known for its simple syntax and readability.
In simple words, Python allows us to give instructions to a computer in a way that is relatively easy for humans to understand.
Imagine you are telling someone:
"Calculate the total price of these three products."
In Python, we can convert that instruction into a small program:
price1 = 500
price2 = 300
price3 = 200
total = price1 + price2 + price3
print(total)
The computer performs the calculation and gives us the result.
Why is Python So Popular?
Python has become one of the most widely used programming languages because it is relatively easy to learn while also being powerful enough for professional development.
📖 Easy to Read
Python syntax is clean and beginner-friendly.
🤖 AI & ML
Python is heavily used in Artificial Intelligence and Machine Learning.
🌐 Web Development
Frameworks such as Django and Flask are used to build web applications.
⚙️ Automation
Python can automate repetitive tasks and business processes.
📊 Data Analysis
Python is widely used for data analysis and visualization.
💻 Career Opportunities
Python skills are useful across software development, automation, data and AI-related roles.
Installing Python and Setting Up Your Environment
Before writing Python programs, you need Python installed on your computer.
You can also use a code editor such as Visual Studio Code to write and execute your Python programs.
Think of Python as the engine that runs your Python programs, while VS Code is like your workspace where you write and organize those programs.
Your First Python Program
One of the first things beginners learn in Python is the print() function.
print("Hello World!")
The print() function displays information on the screen.
If you are building a billing application, you might use:
print("Welcome to KT Store")
print("Your order has been placed successfully")
Python Comments
Comments are notes written inside your program for humans. Python ignores comments while executing the program.
# Calculate total bill
price = 500
quantity = 2
total = price * quantity
print(total)
Imagine opening a Python project after six months. Comments can help you remember what a particular piece of code is doing.
Python Variables
A variable is a name used to store or refer to a value in a program.
name = "Rahul"
age = 25
salary = 50000
Think of variables like labeled boxes.
A box labelled name can contain "Rahul". A box labelled age can contain 25.
Python Data Types
Data types tell Python what kind of value we are working with.
🔢 Integer
Whole numbers such as 10, 25 and 100.
🔣 Float
Decimal numbers such as 10.5 or 99.99.
📝 String
Text such as "Python" or "Hello".
✅ Boolean
Represents True or False.
📋 List
A collection of values that can be changed.
📦 Tuple
A collection of values that cannot be modified after creation.
🔵 Set
A collection designed for unique values.
📚 Dictionary
Stores information using key-value pairs.
Type Casting in Python
Sometimes we need to convert one data type into another. This is called type casting.
age = "25"
age = int(age)
print(age + 5)
Data coming from a form or file is often stored as text. If we receive "25" as a string but want to perform mathematical calculations, we need to convert it into an integer.
Python Operators
Operators allow us to perform calculations and comparisons.
Arithmetic
+, -, *, /, %, //, **
Comparison
==, !=, >, <, >=, <=
Logical
and, or, not
Assignment
=, +=, -=, *=
Suppose an online store gives free delivery when the order value is greater than ₹500.
order_amount = 750
if order_amount >= 500:
print("Free Delivery")
else:
print("Delivery Charges Apply")
if, elif and else
Conditional statements allow a program to make decisions based on different conditions.
Think about an ATM. If the account balance is sufficient, the ATM allows a withdrawal. Otherwise, it shows an error.
balance = 10000
withdraw = 5000
if withdraw <= balance:
print("Please collect your cash")
else:
print("Insufficient balance")
Python Loops
Loops allow us to execute the same block of code multiple times without writing it repeatedly.
For Loop
for i in range(1, 6):
print(i)
Imagine sending an email to 100 customers. Instead of writing the same instruction 100 times, a loop can process each customer automatically.
While Loop
count = 1
while count <= 5:
print(count)
count += 1
Python Lists
A list allows us to store multiple values in a single variable.
products = ["Laptop", "Mouse", "Keyboard"]
print(products[0])
Imagine an online shopping cart. The cart can contain multiple products, so a list is a natural way to represent those products.
Useful List Functions
- len() – finds the number of items
- max() – finds the largest value
- min() – finds the smallest value
- sum() – calculates the total
- sorted() – sorts values
- reversed() – returns items in reverse order
Python Tuples
A tuple is similar to a list, but its elements cannot be changed after the tuple is created.
coordinates = (28.6139, 77.2090)
print(coordinates)
A geographical coordinate such as latitude and longitude can be represented using a tuple when we want to treat those values as a fixed pair.
Python Sets
A set stores unique values.
skills = {"Python", "Java", "Python", "SQL"}
print(skills)
Suppose thousands of employees have entered their programming skills. If you want to find the unique technologies represented in the data, a set can be useful.
Python Dictionaries
Dictionaries store information using key-value pairs.
employee = {
"name": "Rahul",
"age": 28,
"department": "IT",
"salary": 60000
}
print(employee["name"])
Think about an employee record. Instead of remembering that the first value represents the name and the second represents the age, we can use meaningful keys such as name, age and department.
Python Functions
A function is a reusable block of code designed to perform a specific task.
def calculate_total(price, quantity):
return price * quantity
total = calculate_total(500, 3)
print(total)
Imagine a company has to calculate an employee's salary thousands of times. Instead of writing the calculation repeatedly, we can create one function and reuse it whenever needed.
Python Modules and import
As programs become larger, keeping everything inside one file becomes difficult. Python allows us to divide our code into separate modules.
import math
result = math.sqrt(25)
print(result)
Think about a large company. Different teams handle different tasks. Similarly, a large Python project can be divided into multiple modules, with each module handling a particular responsibility.
Understanding Common Python Errors
Making mistakes while learning programming is completely normal. Understanding errors is an important part of becoming a programmer.
NameError
print(username)
Python raises a NameError when it cannot find the name you are trying to use.
AttributeError
An AttributeError generally occurs when an object does not have the attribute or method you are trying to access.
Don't be afraid of error messages. They are actually useful clues that tell you where Python found a problem.
The main function concept
As your Python programs become larger, it is useful to organize the code so that the main execution logic is clearly separated.
def main():
print("Python program started")
if __name__ == "__main__":
main()
Think of a movie. There may be many actors and different scenes, but the movie has a defined starting point. Similarly, the main function can provide a clear starting point for a Python program.
Your Python Learning Journey
Once you understand the basics, you can gradually move toward more advanced Python topics.
🎯 Final Thoughts
Python may look simple when you first start, but it is powerful enough to build real-world applications, automate repetitive work, analyze data and develop Artificial Intelligence and Machine Learning solutions.
The most important thing for a beginner is not to memorize every Python function. Instead, focus on understanding the basic concepts and practice writing small programs.
Start with variables. Then learn data types, operators, conditions, loops, collections, functions and modules. Once these concepts become comfortable, advanced Python becomes much easier.
Remember: Programming is learned by writing code, making mistakes, fixing them and trying again. 🐍💻
🎓 Want to learn Python step by step?
Watch the complete beginner-friendly Python course above and practice each concept along the way.
Follow us