Python First Steps: Your First Lines of Code, No Experience Needed

What programming is and why Python is the language of AI, running Python free in your browser, print, variables, numbers, text and True/False, and reading error messages.

20 min read · Content last verified 20 October 2026 · Reviewed by Shravya M

Before you start

This guide is the reading for Course 1 of the Python for AI Pathway. It takes about 20 minutes. No coding experience is needed. If you already program in another language, skim it quickly; the later courses get more technical.

You'll learn what programming is, why Python is the language of AI, how to run Python for free in your browser, and your first real lines of code.

All names and examples here are made up.

Chapter 1: What programming is, and why Python

Programming means writing instructions for a computer, step by step, in a language it can follow. A program is a set of those instructions.

Python is a programming language designed to be easy to read. A line of Python often looks almost like English, which is why it's a favourite for beginners.

It's also the main language of AI. The tools used to train models, analyse data and call models like ChatGPT or Gemini are mostly written for Python. Learning it opens the door to everything in the AI Foundations Pathway, hands-on.

You don't need to be a "computer person". If you can follow a recipe, you can follow a program.

The rule: Code is just instructions, run from top to bottom, one line at a time.

Chapter 2: Running Python for free

You don't need to install anything. The easiest way to start is Google Colab (colab.research.google.com):

  1. Sign in with a Google account.
  2. Click New notebook.
  3. Type code into a cell (a grey box).
  4. Press Shift + Enter to run it. The result appears just below.

A notebook is a page of cells, so you can write a little code, run it, look at the result, and carry on. Everything in this pathway works in Colab.

You can also install Python on your own computer from python.org, but Colab is the quickest start, and it already includes the AI libraries used later in this pathway.

Chapter 3: Your first line: print

Type this into a cell and run it:

print("Namaste, Python!")

Output:

Namaste, Python!

print shows something on the screen. The text inside the quotation marks is called a string (a piece of text).

Lines starting with # are comments: notes for humans, which Python ignores.

# This line is a note and does nothing
print("Comments help explain your code")

Chapter 4: Variables: giving names to values

A variable is a name that stores a value, like a labelled box:

name = "Asha"
age = 21
city = "Pune"
print(name, "is", age, "years old and lives in", city)

Output:

Asha is 21 years old and lives in Pune
  • The = sign means "store this value under this name". It is not "equals" as in maths.
  • Names can't have spaces; use underscores, like monthly_income.
  • Python is case-sensitive: Age and age are different names.

You can change a variable later, and the newest value wins:

age = 21
age = age + 1
print(age)

Output:

22

Chapter 5: Numbers, text and True/False

Python has a few basic data types:

TypeExampleUsed for
int (whole number)25Counts, ages
float (decimal number)99.5Prices, marks, measurements
str (string, text)"Mumbai"Names, messages
bool (True/False)TrueYes/no answers

Maths works as you'd expect:

rent = 12000
food = 6500
travel = 1800
total = rent + food + travel
print(total)
print(total / 3)

Output:

20300
6766.666666666667

Useful operators: + add, - subtract, * multiply, / divide, ** power, and % remainder.

To mix text and numbers neatly, use an f-string: put f before the quotes and the variable in {}:

total = 20300
print(f"My monthly spending is Rs {total}")

Output:

My monthly spending is Rs 20300

Comparing values gives True or False:

marks = 72
print(marks >= 40)
print(marks > 90)

Output:

True
False

Chapter 6: Errors are normal

Every programmer sees errors every day. An error message is Python telling you exactly what it couldn't understand. For example:

print("Hello"

Python reports a SyntaxError, because the closing bracket is missing. Read the last line of an error message first; it usually says what went wrong.

Common beginner errors:

  • SyntaxError: a typo, such as a missing bracket or quote.
  • NameError: you used a variable name before creating it, or spelled it differently.
  • TypeError: you mixed types that don't go together, like adding text to a number ("Age: " + 21). Use an f-string instead.

The rule: Read the last line of the error, fix one thing, run again.

Chapter 7: Python, AI and you

Why learn this if you don't work in IT?

  • Automate dull work: tidy a spreadsheet, rename hundreds of files, total up expenses.
  • Understand AI properly: you'll see how models are trained and used, not just read about it.
  • Talk to technical teams: knowing the basics makes you far more effective at work.
  • Build small tools: a script that sorts your photos, or checks a list of prices.

And if you are in IT, Python is the shortest route into data and AI work.

The next courses build step by step: Course 2 adds lists, decisions and loops; Course 3 works with real data; Course 4 trains a machine learning model; Course 5 uses AI models from Python.

Key words

  • Program: a set of instructions for a computer.
  • Python: an easy-to-read programming language, the main language of AI.
  • Google Colab: a free website to write and run Python in your browser.
  • Notebook / cell: a page of code boxes you run one at a time.
  • print: shows a value on the screen.
  • Comment: a note in code, starting with #, that Python ignores.
  • Variable: a name that stores a value.
  • String, int, float, bool: text, whole number, decimal number, True/False.
  • f-string: text with values inserted, written f"...{name}...".
  • Error message: Python explaining what it couldn't understand.

Sources

Checked against these primary sources on 20 October 2026. Rules change: if something here looks out of date, trust the source.

More free guides