Before writing a single line of code, it helps to know how the fields you are about to learn fit together. Think of them as concentric circles.
Python dominates this world because it is easy to read and comes with a huge ecosystem of scientific libraries such as NumPy, Pandas, Matplotlib, scikit-learn, and TensorFlow. Your job in this book is to become fluent in the core language first, because every AI library you meet later is just Python.
Anaconda is a free distribution of Python that bundles the interpreter, hundreds of scientific packages, and the conda package manager in one installer. It avoids the classic beginner pain of manually installing NumPy, Matplotlib and friends one at a time.
python --version. You should see a Python version number in response.conda is not recognized appears, skip ahead to the PATH section below. It is one of the most common first-day hurdles and the fix is simple.
VS Code is a free, lightweight editor that is ideal for AI work. Once installed, add these things to make it productive:
.ipynb) directly in the editor.A good workflow is: write a script in the editor, press the run button, and read the output in the integrated terminal. Keep the Explorer sidebar open so your projects stay organised.
A virtual environment is an isolated copy of Python with its own installed packages. Different projects can therefore use different library versions without breaking each other. If project A needs NumPy 1.x and project B needs NumPy 2.x, each keeps its own copy happily inside its own environment.
Anaconda users create environments with conda:
conda create --name ai-course python=3.11
conda activate ai-course
conda install numpy pandas matplotlib
If you installed Python directly (no Anaconda), the built-in venv module does the job:
python -m venv myenv
myenv\Scripts\activate
pip install numpy
On macOS and Linux the activate command is source myenv/bin/activate.
pipenv combines environment creation and dependency tracking in one tool. It keeps a Pipfile that records your packages:
pip install pipenv
pipenv install pandas
pipenv shell
This error simply means the operating system cannot find the conda command because its folder is not listed in the system PATH. PATH is the list of folders the system searches whenever you type a command.
conda.exe. With a typical Anaconda install on Windows it lives inside the Scripts sub-folder of your Anaconda folder.Path in the user list, then click Edit and New to add the Scripts folder path.conda --version to confirm the fix.On macOS and Linux, add the equivalent line to your shell profile file:
export PATH="/path/to/anaconda3/bin:$PATH"
Every programming language has two layers: syntax is the grammar of the language (what the code looks like), and semantics is the meaning (what the code does).
Python uses indentation instead of curly braces to mark blocks. Every line inside a block must be indented with the same number of spaces:
score = 82
if score >= 70:
print("You passed") # indented: inside the if
print("Thanks") # not indented: outside the if
A comment is text the interpreter ignores. Use # for a line comment and triple quotes for a multi-line docstring-style comment:
# this line does nothing
name = "Ada" # inline comments explain the line
"""This is a longer comment
that spans several lines."""
An expression is any piece of code that produces a value, such as 3 * 4 or "hi" + " there". A statement is an instruction that performs an action, such as print(...), an if block, or an assignment. Expressions appear inside statements all the time.
Python decides variable types at run time, so you never declare them. The same name can hold an integer and later a string:
value = 10 # an integer
value = "ten" # now a string - perfectly legal
print(value)
This flexibility is convenient but means you must keep track of what each variable holds, because mistakes only surface when the code runs.
practice, install nothing yet, and confirm it activates. Then open VS Code, create a file called hello.py with two expressions and two statements, and run it. Finally, fix the PATH if any command is not recognised before moving to Chapter 2.