indusai.co

Introduction to Python

Python is a general purpose programming language that reads almost like plain English. It was created by Guido van Rossum and first released in 1991, and today it is the most widely used language for data analysis, machine learning, automation and web backends.

Why learn Python

  • Readable syntax. Python uses indentation instead of braces and semicolons, so code looks clean and is easy to follow.
  • Batteries included. The standard library covers files, dates, maths, networking, JSON and much more without installing anything.
  • Huge ecosystem. NumPy, pandas, scikit-learn, PyTorch, Django, FastAPI and thousands of other packages are one pip install away.
  • Runs everywhere. Windows, macOS, Linux, servers, Raspberry Pi and, as you will see on this site, even inside your browser.

Your first program

Every programming journey starts the same way. Press Run on the block below.

python
print("Hello, World!")
output
Hello, World!

print() is a built in function that writes text to the screen. The text inside the quotes is a string. You will meet both again very soon.

What Python looks like

Here is a slightly bigger example so you can see the shape of the language. Do not worry about understanding every line yet; every idea in it has its own lesson later.

python
students = ["Aarav", "Diya", "Kabir"]

for name in students:
    if name.startswith("A"):
        print(name, "comes first alphabetically")
    else:
        print(name)

print("Total students:", len(students))

Notice three things:

  1. There are no semicolons and no curly braces.
  2. The lines inside the for loop and the if statement are indented. Indentation is how Python knows which lines belong together.
  3. Variables like students are created simply by assigning to them. You do not declare a type first.

Python 2 and Python 3

You may still see Python 2 code online. Python 2 reached end of life in 2020 and should not be used. Everything on this site is written for Python 3.10 or newer.

How to use this resource

Each lesson is short and builds on the previous one. Code blocks with a Run button execute right here in your browser, so read the code, predict what it will print, then run it to check. At the end of most lessons there is a short practice section. Doing those is what actually makes the ideas stick.

Practice

  1. Change the greeting above to print your own name.
  2. Add a fourth student to the students list and run the loop again. Did the total update by itself?