Python Introduction

Python Beginner 4 min read Published
In this lesson

Python is a programming language known for being easy to read and powerful at the same time. It’s the most popular language for beginners, and also one of the most used by professionals: in data science, AI and machine learning, automation, web back-ends and scientific research.

Your first Python program#

print("Hello, world!")
print(2 + 3)
print("Python", "is", "fun")

Output:

Hello, world!
5
Python is fun

print() shows a value on the screen. Passing several values separated by commas prints them with spaces in between. Compared with many languages, there’s very little extra: no semicolons, no curly braces, no main function required.

Why Python is beginner-friendly#

Here’s a program that greets a list of people:

names = ["Asha", "Rohan", "Meera"]

for name in names:
    if name.startswith("A"):
        print(f"Hello, {name}! Your name starts with A.")
    else:
        print(f"Hi, {name}!")

Even without knowing Python, you can probably guess what it does. That readability is Python’s main design goal: code is read far more often than it’s written.

Indentation is part of the language#

Notice the spaces at the start of some lines. In Python, indentation defines blocks of code. The lines indented under for belong to the loop; the lines under if belong to the condition.

age = 20
if age >= 18:
    print("You can vote.")      # inside the if (4 spaces)
    print("Don't forget your ID.")
print("This always runs.")       # back at the left: outside the if

Other languages use { } for blocks and indentation is just style. In Python it’s required, which forces everyone’s code to be neatly formatted. The standard is 4 spaces per level; your editor inserts them when you press Tab.

What people build with Python#

AreaExamplesPopular libraries
AI and machine learningChatbots, image recognition, recommendationsPyTorch, scikit-learn, Transformers
Data analysisSales reports, charts, cleaning spreadsheetspandas, NumPy, Matplotlib
AutomationRenaming 1,000 files, filling forms, sending reportsbuilt-in modules, Selenium
Web back-endsAPIs and websites (Instagram, Pinterest)Django, Flask, FastAPI
Scripting and DevOpsServer tasks, deployment toolsbuilt-in modules
Education and scienceSimulations, researchJupyter notebooks

Learning Python opens all these doors, and it’s the main language for working with AI.

Python is interpreted#

You don’t compile Python into a program file first. The Python interpreter reads your code and runs it line by line. That makes it quick to experiment: write a line, run it, see the result.

The trade-off: pure Python is slower than languages like C or Go. In practice, heavy work (maths, AI) is done by libraries written in fast languages, and Python acts as the easy-to-write “glue”.

Python 3#

There were two major versions: Python 2 and Python 3. Python 2 reached its end of life in 2020. Everything in this course is Python 3, and that’s the only version you should learn. If an old tutorial writes print "hello" without brackets, it’s Python 2.

Comments#

# This is a comment. Python ignores it.
print("Comments explain why the code does something.")  # comments can go here too

Where Python runs#

  • On your computer, after installing it (next lesson).
  • In the browser, with free tools like Google Colab, Replit or Programiz Online Compiler. Great for practising right now.
  • On servers, in the cloud, even on small devices like the Raspberry Pi.

Note: Python examples on VitalStack don’t have a Try it Yourself button (that runs only HTML and JavaScript). Copy them into an online Python editor or your own computer.

How to learn effectively#

  • Type the examples yourself instead of copy-pasting. Your fingers learn the syntax.
  • Change things and predict the output before running.
  • Read error messages from the bottom up: the last line says what went wrong; the lines above say where.
  • Build tiny projects as soon as possible: a tip calculator, a quiz, a file renamer.

Common mistakes#

  • Inconsistent indentation (mixing tabs and spaces, or 2 and 4 spaces) → IndentationError.
  • Missing colon at the end of if, for, def lines → SyntaxError.
  • Capital letters: Print() is not print(). Python is case-sensitive.
  • Following Python 2 tutorials.

Exercise#

  1. Open an online Python editor (or install Python in the next lesson) and print your name.
  2. Print the result of 365 * 24 (hours in a year).
  3. Print three words on one line using commas in print().
  4. Change the greeting program to greet four people, with a special message for names starting with “R”.

Summary#

  • Python is readable, beginner-friendly, and used for AI, data, automation and the web.
  • print() shows output; indentation (4 spaces) defines code blocks.
  • Learn Python 3 only.
  • Practise in an online editor or on your own computer.

Next, you’ll install Python and set up an editor.

Quick quiz

3 questions. Check what stuck and earn 2 XP for each right answer.

1What does indentation do in Python?
2Python is…
3How do you write a comment?

Progress is saved in this browser. Create a free account to keep it on every device.