Python Getting Started · Lesson 1 of 149

Python Getting Started

What you will learn

  • What Python is and what programs are made of
  • Two ways to run Python code
  • How to write, save and run your first program
  • What print does

1. What Python is

Python is a programming language. A program is a list of instructions the computer follows, one after another. Python is popular for beginners because its instructions read close to plain English, and it is used for websites, data analysis, automation, science and more.

You write instructions in a text file, and Python reads and runs them from top to bottom.

2. Getting Python

Download Python from the official website, python.org, and install it. On the installer, tick the option that adds Python to your PATH (on Windows), so that you can run it from a terminal.

Then open a terminal (Command Prompt, PowerShell or Terminal) and check that it works:

python --version

It should print a version number such as Python 3.13.7. Your number may differ, and any recent Python 3 is fine for this course. On some systems the command is python3 instead of python.

You can also ask Python for its own version from inside a program. The cell below runs real Python right here in your browser, so you can try it now (press Run):

import sys
print(sys.version.split()[0])

Output:

3.13.2

That is the Python your browser runs for the examples on this site (Python 3.13). The Python on your own computer may have a different number, and that is fine.

3. Two ways to run code

A. The interactive prompt. Type python and press Enter. You see >>>, where you can type one line at a time and see the result immediately. Type exit() to leave. This is great for trying small ideas.

B. A file. Write your program in a file ending in .py, and run it with python filename.py. This is how real programs are run.

4. Your first program

Create a file called hello.py containing:

print("Hello, world!")

Run it:

python hello.py

Output:

Hello, world!

What happened:

  • print is a function that shows something on the screen.
  • The text in quotation marks, "Hello, world!", is a string: a piece of text.
  • The brackets ( ) hold what you give to the function.

Try it here. Python examples on this site can run in your browser, with nothing to install. Every example in this course is a cell: press Run under In [ ], click the code to edit it, and the result appears right below it, as in a notebook. The cells of a lesson share one Python session, so a variable made in one cell can be used in the next. Run all at the top of the lesson runs every cell in order, and Open in playground opens an example in a full editor (several files, input(), charts). Examples that ask you to type, use the network, start threads or work with files on your own computer need a real Python there, so those stay plain code with a short note.

Good to know. The Python in your browser is the real Python 3.13, but it is a 32-bit build running inside the browser. So a few results differ from a normal computer: sizes in bytes from sys.getsizeof are smaller, file paths use /, the addresses in lines such as <function f at 0x...> change on every run, and timings depend on your machine. The output printed under each example in the lesson was made on a Windows computer.

5. A few more lines

Programs run top to bottom, one line at a time:

print("Hello, world!")
print("Welcome to Pathkori")
print(2 + 3)

Output:

Hello, world!
Welcome to Pathkori
5

Notice that print(2 + 3) shows 5: Python calculated the sum before printing it. And print("2 + 3") with quotation marks would show the text 2 + 3 instead, because it is a string, not a calculation.

Worked example: a small study plan

Put several print lines together to make a tiny program. It mixes text and a calculation:

print("Pathkori study plan")
print("Lessons per week:", 3)
print("Weeks:", 4)
print("Lessons in total:", 3 * 4)

Output:

Pathkori study plan
Lessons per week: 3
Weeks: 4
Lessons in total: 12
Line What it shows
print("Pathkori study plan") a heading: text in quotation marks is printed as it is
print("Lessons per week:", 3) text, then a number; print puts a space between the two
print("Lessons in total:", 3 * 4) Python calculates 3 * 4 first, then prints 12

Change the numbers and run the program again: that is the quickest way to learn.

Common mistakes

  • Forgetting the quotation marks around text.
  • Saving the file as hello.py.txt (the editor hides the extension).
  • Typing python in the wrong folder, so it cannot find your file. Use the terminal's current folder, or give the full path.
  • Typing the prompt >>> as part of the code.
  • Using curly "smart quotes" copied from a document. Python needs straight quotes, " or '.

Key takeaways

  • Python runs your instructions from top to bottom.
  • You can type single lines at the >>> prompt or run a whole .py file.
  • print(...) shows a value on the screen.
  • Text goes in quotation marks; numbers and calculations do not.

Practice

1. Write a program that prints your name.

Show answer

For example print("Rina"), with your own name in the quotation marks.

2. What does print(4 * 5) show? What does print("4 * 5") show?

Show answer

20, then the text 4 * 5. Without quotes Python calculates; with quotes it prints the text exactly.

3. Why does the order of lines in a program matter?

Show answer

Python runs the lines from top to bottom, so changing the order changes what happens first.

4. What command runs a file named app.py?

Show answer

python app.py (or python3 app.py on some systems).

5. What is the difference between a string and a calculation in a print?

Show answer

A string is text in quotation marks and is printed exactly as written. A calculation such as 2 + 3 has no quotation marks, so Python works it out and prints the result.

6. What does print("Lessons:", 3 * 4) show?

Show answer

Lessons: 12. The text is printed, then a space, then the result of the calculation.