CodingNic

Getting Started with Python

Python History and Installation

Getting Started with Python 10 min read

Python History and Installation

Objectives

By the end of this chapter, you should be able to:

  • Explain what Python is used for
  • Explain why this course teaches Python 3
  • Install Python and run your first script

💡 Why this matters: Everything else in this course assumes Python 3 is installed and working on your machine.

What Is Python?

Python is a general purpose programming language used for web backends, data science, automation, and more. It has a reputation for being readable and beginner friendly.

Python 3, Not Python 2

Python 2 is no longer maintained. This course teaches Python 3, the current standard.

Installing Python

  1. Download Python 3 from python.org.
  2. Confirm the install by running this in your terminal:
bash
python3 --version
  1. Confirm pip3 (Python’s package manager) is available too:
bash
pip3 --version

Running Python Code

There are two ways to run Python code.

The REPL (type python3 with nothing after it) is an interactive prompt. You type one line, press Enter, and see the result immediately. It’s good for quick checks.

bash
python3
>>> 2 + 2
4
>>> exit()

A script is a file ending in .py that holds all your code at once. This is how real programs run.

bash
python3 first.py

Try it now. Create a file called first.py with one line:

python
print("Hello, Python")

Then run it:

bash
python3 first.py
# Hello, Python

Virtual Environments

Every project eventually needs third-party packages. Installing them globally causes conflicts once you have more than one project (Project A needs version 1 of a library, Project B needs version 2). A virtual environment gives each project its own isolated packages.

bash
python3 -m venv env       # create it
source env/bin/activate   # activate it (macOS/Linux)
env\Scripts\activate      # activate it (Windows)
deactivate                 # leave it

Create a fresh virtual environment for every project.

Saving Your Dependencies

Once a project has packages installed, record them so anyone can recreate the same setup:

bash
pip freeze > requirements.txt
pip3 install -r requirements.txt   # recreates the environment elsewhere

Python’s Built-In Data Types

A preview. Each of these gets its own lesson soon.

Type Example
bool True, False
int / float 4, -10, 1.3
str "hi"
list [1, 2, 3]
tuple (4, 2, 1)
set {"a", "b", "c"}
dict {"key": "value"}

Try It

  1. Run python3 --version in your terminal.
  2. Create first.py with print("Hello, Python") and run it.
  3. Create a virtual environment with python3 -m venv env, then activate it. Your terminal prompt should change to show (env). Run deactivate to leave it.

Recap

  • This course teaches Python 3.
  • python3 opens a REPL; python3 file.py runs a script.
  • python3 -m venv env creates an isolated environment per project.
  • pip freeze > requirements.txt records your project’s dependencies.

Next lesson: variables, and the rules for naming them well.