Python is a readable, general-purpose programming language used for websites, automation, data analysis and machine learning. This guide is a learning path: how to set up Python properly, the core language, the advanced features worth knowing, testing, and the main frameworks for web and data work, with short examples throughout. It ends with where you can run Python on Domain India.
Install a currently supported Python 3 release and create a virtual environment for every project, with venv and pip or a faster tool such as uv. Learn the core language first (variables, types, conditions, loops, functions, exceptions, lists and dictionaries), then comprehensions, generators, decorators, type hints and classes. Test with pytest. For the web, choose Django, Flask or FastAPI; for data, pandas and NumPy; for machine learning, scikit-learn and PyTorch.
1. Set up Python the right way
Use a Python 3 release that still receives security updates; the python.org downloads page lists which ones do. Python 2 reached end of life in 2020, so skip any tutorial written for it.
| Tool | What it does | Use it when |
|---|---|---|
| venv + pip | Built-in virtual environments and the standard package installer | Always available; the safe default |
| uv | A fast installer and project manager that also manages Python versions | New projects where speed and lock files matter |
| conda | Environments that include non-Python libraries | Data science with heavy compiled dependencies |
A virtual environment keeps each project's packages separate, so upgrading one project never breaks another:
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install requests
pip freeze > requirements.txt # record exact versionsNever install project packages into the system Python with sudo pip. Many Linux systems now block it for that reason.
2. The core language
name = "Asha" # str
orders = 3 # int
total = 2499.50 # float
is_active = True # bool
if orders > 2 and is_active:
print(f"{name} is a regular customer")
elif orders == 0:
print("New customer")
else:
print("Occasional customer")
for i in range(3):
print(i)
while orders > 0:
orders -= 1Python uses indentation, not braces, to mark blocks, so keep it consistent (four spaces). Variables have no declared type; the value decides the type.
Functions and exceptions
def average(values: list[float]) -> float:
"""Return the mean of a non-empty list."""
if not values:
raise ValueError("values must not be empty")
return sum(values) / len(values)
try:
print(average([]))
except ValueError as err:
print(f"Could not calculate: {err}")
finally:
print("Done")Catch the specific exceptions you expect. A bare except: hides real bugs.
3. Collections: lists, tuples, sets and dictionaries
| Type | Example | Ordered | Changeable | Typical use |
|---|---|---|---|---|
| list | [1, 2, 3] | Yes | Yes | A sequence you add to or sort |
| tuple | ("Pune", 411001) | Yes | No | A fixed record |
| set | {"php", "python"} | No | Yes | Unique items, fast membership tests |
| dict | {"name": "Asha", "city": "Pune"} | Insertion order | Yes | Look up values by key |
Knowing which to use is most of everyday data-structure work. Python's standard library adds more: collections.deque for queues, heapq for priority queues and collections.Counter for counting. Classic algorithm topics such as sorting, searching, recursion and trees are worth studying, but in real code use the built-in sorted() and bisect rather than writing your own.
4. Advanced features worth learning
- Comprehensions build collections in one readable line:
squares = [n * n for n in range(10) if n % 2 == 0]. - Generators produce values one at a time, so a large file or data stream never has to fit in memory:
def read_lines(path):
with open(path, encoding="utf-8") as f:
for line in f:
yield line.rstrip("\n")- Context managers (
with) close files and connections even when an error occurs. - Decorators wrap a function to add behaviour such as timing, caching or access checks;
functools.cacheis a built-in example. - Lambdas are small unnamed functions, handy as a
keyfor sorting:sorted(users, key=lambda u: u["age"]). - Type hints (
def f(x: int) -> str:) document your code, and tools such as mypy or your editor use them to catch mistakes early. - Regular expressions with the
remodule match and extract patterns in text. - Concurrency: use
asynciofor many network requests at once,concurrent.futures.ThreadPoolExecutorfor blocking I/O, andmultiprocessingfor CPU-heavy work. Recent Python versions also offer an optional free-threaded build, but most code still runs on the standard one.
5. Object-oriented Python
from dataclasses import dataclass
@dataclass
class Product:
name: str
price: float
def with_gst(self, rate: float = 0.18) -> float:
return round(self.price * (1 + rate), 2)
class DigitalProduct(Product):
def delivery(self) -> str:
return "Download link by email"
item = DigitalProduct("E-book", 499)
print(item.with_gst(), item.delivery())Classes group data with the methods that act on it; inheritance lets a subclass reuse and extend a parent. Magic methods such as __str__, __eq__ and __len__ make your objects behave like built-in types. Prefer dataclass for classes that mainly hold data.
6. Testing
# test_prices.py (run with: pytest)
from shop import average
def test_average():
assert average([10, 20]) == 157. Automation
Python is ideal for jobs you would otherwise do by hand:
- Files:
pathlibandshutilrename, move and organise files;csvandopenpyxlread and write spreadsheets. - The web:
requestsorhttpxcall APIs; Beautiful Soup parses HTML. Check a site's terms androbots.txtbefore scraping it, and use an official API where one exists. - Browsers: Playwright automates a real browser for testing or form-filling.
- Networks and servers: Paramiko and Netmiko run commands over SSH; Ansible, itself written in Python, automates server setup.
8. Web frameworks and data science
| Library | Best for |
|---|---|
| Django | Full websites with an admin panel, user accounts and an ORM built in |
| Flask | Small, flexible apps and simple APIs |
| FastAPI | Fast, typed JSON APIs with automatic documentation |
| pandas / Polars | Tables of data: cleaning, joining, summarising |
| NumPy | Fast numerical arrays; the base of most scientific libraries |
| scikit-learn | Classic machine learning: classification, regression, clustering |
| PyTorch / TensorFlow | Deep learning and neural networks |
Learn one web framework and pandas well before spreading wider. For project ideas, see Python project ideas to build your skills, and for where each library is used, Python use cases.
9. Running Python on Domain India
Measured on our servers in September 2026:
- cPanel shared hosting has Setup Python App, with Python 3.9, 3.11 and 3.12, for Django, Flask and similar web apps. DirectAdmin offers Python 2.7 and 3.8 to 3.13 through its application selector. Webuzo has no such tool that we could confirm, so ask support. See deploy a Python app on shared hosting.
- Shared hosting runs web apps, not long-running workers or heavy data jobs. Cron jobs run at most every 4 minutes. Jailed SSH access is available on every shared plan; it is off by default, so ask support to enable it.
- The App Platform runs Python apps in their own container from a Dockerfile you provide. See getting started with the App Platform.
- A VPS is self-managed, with root access for any Python version, background workers and data jobs. See FastAPI production deployment.
The cards show live Domain India prices, excluding 18% GST.
- 512 MB RAM per app
- 1 vCPU
- 5 GB NVMe SSD
- PostgreSQL Database
- 1 vCPU
- 2 GB DDR4 RAM
- 64 GB NVMe SSD Storage
- 2 TB Monthly Bandwidth
Frequently asked questions
Which Python version should I learn?
A current Python 3 release that still receives security updates; python.org lists them. Python 2 reached end of life in 2020 and should not be used for new work.
What is a virtual environment and why do I need one?
A virtual environment is a private folder of packages for one project. It stops projects from breaking each other when they need different package versions. Create one with python3 -m venv .venv, or let a tool such as uv manage it.
Should I use pip, uv or conda?
pip with venv works everywhere and is the safe default. uv is a much faster alternative that also manages Python versions and lock files. conda suits data science projects that depend on large compiled libraries.
Which Python web framework should I choose?
Django for full websites with accounts and an admin panel, Flask for small flexible apps, and FastAPI for typed JSON APIs.
Can I run a Python website on Domain India shared hosting?
Yes, on cPanel and DirectAdmin servers. cPanel's Setup Python App offers Python 3.9, 3.11 and 3.12, and DirectAdmin offers 2.7 and 3.8 to 3.13. For background workers or heavy jobs, use the App Platform or a VPS.
How do I test Python code?
Write unit tests with pytest: small functions whose names start with test_ and which use assert. Run pytest in the project folder, and add integration and end-to-end tests as the project grows.
Ready to build something in Python? Read deploy a Python app on shared hosting, compare the App Platform and VPS plans, or open a ticket if you need help choosing.
Deploy Python apps from a Dockerfile, with free SSL and a PostgreSQL database, and no server to manage.
See the App Platform