Loading...

Python essentialsGetting Started

Introduction to Python

4 min lesson

Next
  • Python is a programming language: a way to give clear instructions to a computer so it can do tasks for you.
  • People use Python for websites, data analysis, automation, games and scientific work because it is readable and friendly for beginners.
  • Think of Python as a recipe book: you write steps in order, and the computer follows them exactly like a cook.
  • A program is a list of instructions; code is the text you write; running means the computer executes your instructions.
  • Python reads your code line by line from top to bottom, doing each step before moving to the next.
  • You write Python in plain text files ending with .py, and a program called the Python interpreter turns your text into actions.
  • A real use: a small script can rename hundreds of photos or calculate a shopping total in seconds.
  • Python cares about indentation (spaces at the start of a line), so layout matters more than in many other languages.
  • This is the first step; next you will install Python, then write your first program.
Keep in mind
  • Python is a readable language that tells the computer what to do step by step.
  • You write code in .py files and the Python interpreter runs it.
  • Indentation (spaces at the start of lines) is meaningful in Python, so keep it tidy.
  • Mistakes are normal and part of learning; run small programs often and you will improve quickly.

Breaking it down

Program

print("Hello")

A program is a list of instructions. This one-line program tells Python to show text on screen. Without any instructions, the computer would do nothing.

Interpreter

python3 main.py

The interpreter is the program that reads your .py file and performs each instruction. Without it, your text file would just sit there as plain text.

Indentation

print("Hi")

Spaces at the start of a line show which lines belong together. Python uses indentation instead of curly braces. Wrong indentation causes an IndentationError.

Python vs other languages

FeaturePythonC (for comparison)
ReadabilityVery high, looks like EnglishLower, more symbols
TypingDynamic (types checked at run time)Static (types checked at compile time)
IndentationRequired and meaningfulNot required, uses braces
SpeedSlower for heavy number crunchingFaster for low-level tasks

A helpful analogy

Python is like a recipe: the ingredients are your data, the steps are your instructions, and the interpreter is the cook who follows them exactly. If a step is unclear, the cook stops and asks (an error). Keeping steps in order and indented neatly helps the cook work smoothly.

Nesting rules

  • 1.Indent consistently with 4 spaces per level; mixing tabs and spaces causes errors.
  • 2.A colon (:) at the end of a line (like if x > 0:) means the next indented block belongs to it.
  • 3.Keep lines short and simple; one instruction per line is easiest to read.

Common mistakes

Using the wrong indentation

Avoid

if True: print("Hi") // IndentationError

Use instead

if True: print("Hi")

Python uses indentation to know which lines belong inside a block. Without the 4 spaces, Python raises an IndentationError.

Forgetting quotes around text

Avoid

print(Hello) // NameError

Use instead

print("Hello")

Text must be inside quotes. Without quotes, Python looks for a variable named Hello and fails with NameError.

Quick tips

  • •Type code by hand instead of copying; your fingers learn the patterns.
  • •Run your program after every few lines so errors are easy to find.
  • •Read error messages from the bottom up; the last line often explains the problem.
  • •Try changing text inside print() and run again to see what happens.
Next