Python_Crash_Course_1738153616
Python_Crash_Course_1738153616
All material in this book is protected by copyright unless otherwise noted. If you
received this book without purchasing it, please consider supporting future books
30-day free trial, so you can explore our courses and join a community of learners.
Every subscription directly contributes to the creation of more resources like this.
Our books and courses are available for educational, business, or promotional use,
i
ii
About the Author
from Centrale Lille, France. With 15+ years in software engineering and machine
learning, along with a decade in project management and leadership, he now helps
engineers and researchers master Python, Rust, and C/C++ for engineering and
iii
iv
Contents
1 Welcome 1
v
vi
1 Welcome
To learn a programming language like Python, first, you need to familiarise yourself
with its core concepts and syntax. Once you’re comfortable with the language,
In this course, we’ll cover the essentials in just two hours, providing you with a
solid foundation to start coding with confidence. For more advanced topics in
engineering and scientific simulations, additional courses and books are available
at TechEngineer.org.
This course is designed for engineers, researchers, and developers who already
practice is the most effective way to understand and retain new concepts. You
can learn by following the e-book or watching the videos, but the key to success
TechEngineer.org 1
1.3 About Tech Engineer
Tech Engineer offers practical, hands-on training in Python and Rust, specialising
Join the Tech Engineer Community for support—it’s easy and free!
For full access to expert support and premium resources to accelerate your learn-
2 TechEngineer.org
2 Getting Started with Python
Python, created by Guido van Rossum in 1991, is a widely used programming lan-
guage praised for its simplicity, readability, and versatility. Its clean syntax makes
it easier to read and write code compared to languages like C, C++, or Rust.
that make it ideal for projects in data analysis, web development, and machine
learning.
Popular platforms like YouTube, Instagram, and Dropbox have been developed
using Python, showcasing its ability to handle complex, large-scale systems. Its
versatility and ease of use also make it a preferred choice for scientific computing,
TechEngineer.org 3
2.1 Python Installation and Considerations
There are many ways to install Python, but we recommend using the uv package
manager for the best experience. Other options like conda, pyenv, or the official
installers from Python.org are reliable and effective but may become limiting as
For now, don’t worry about the details! Relax and focus on learning as much as
you can about Python. Remember, everything is reversible and can be changed.
If you prefer using conda or pyenv, feel free to experiment—that’s perfectly fine.
• Replacing several tools like conda, pyenv, pip, poetry, virtualenv, and more
The steps for installing uv and running Python code can seem intimidating if you’re
not familiar with using the terminal. Don’t worry! To navigate this process without
stress, we recommend that you always read the messages that appear after you
do a quick online search, and you may be surprised at how quickly you can find
4 TechEngineer.org
1 Installing uv
To install uv, open the Terminal or PowerShell and paste the following code:
Windows
� Important
Follow the PowerShell instructions to validate the installation.
� Note
For more details and assistance with installing uv, please refer to the
2 Installing Python
Once we’ve installed uv, we’re ready to install Python to begin our journey!
TechEngineer.org 5
2.3 Running Python Code
Python provides several tools and environments for writing and executing code,
We’ll explore three methods for running Python code: the Python interpreter for
Future courses will include advanced configurations using tools such as VS Code
The Python interpreter is the simplest way to execute Python code directly. It
allows you to run commands line by line and is ideal for quick testing and simple
scripts. The standard Python interpreter is included with Python installations and
1 Launching Python
uv run python
uv run python
6 TechEngineer.org
2 Hello, world!
Tradition suggests that the first program in a new language should print the
print("Hello, world!")
Type it into the Python interpreter, and you should see the following output:
uv run python
1 + 2 + 3 + 4 + 5
uv run python
TechEngineer.org 7
2.3.2 The IPython Interpreter
IPython is a powerful interactive Python shell that provides a rich environment for
completion, syntax highlighting, and the ability to execute code line by line or cell
by cell.
When learning Python, IPython can be invaluable for testing code snippets, visu-
alising data, and understanding the immediate impact of changes. It’s a great tool
1 Installing IPython
To install IPython using uv (see the previous section), enter the following
To complete the setup, update your shell PATH with this command:
uv tool update-shell
� Important
You might need to restart your Terminal for the changes to work.
2 Launching IPython
ipython
8 TechEngineer.org
You’ll see something like this:
ipython
Remember the classic ”Hello, world!”? It’s a great start, but let’s dive into
IPython’s tab completion helps you gain efficiency by letting you complete
code with just a tap of the Tab key. This simple action reduces typos and
saves time.
For instance, if you want to type print, start by entering pr in the IPython
interpreter and press Tab . Instantly, a list of options starting with pr will
appear:
In [1]: pr
print() property %precision %prun
In [2]:
TechEngineer.org 9
4 Discovering Object Attribute Completion
Imagine you’re building a Lego castle. Each Lego brick is an object, and come
Attributes describe what an object is, such as its color, size, or shape.
To build your castle, you also need to know what each Lego brick can do.
For example, some bricks can snap together, while others might have special
hinges. In Python, these actions are called methods. Methods tell you what
IPython’s object attribute completion is a handy tool that helps you easily
In [3]:
When you type legos. and press the Tab , IPython will show a list of attrib-
In [3]: legos.
append() count() insert() reverse()
This way, you can quickly see what you can do with the legos list without
Why is it useful?
10 TechEngineer.org
2.3.3 The JupyterLab
combine code, text, equations, and rich visuals. It provides Python learners with
1 Installing JupyterLab
This will install JupyterLab with the Altair extension that allows us to create
interactive visualisations.
� Note
2 Launching JupyterLab
jupyter-lab
This will launch the JupyterLab server and automatically open it in your web
TechEngineer.org 11
Menu bar Main work area
Left sidebar
3 Exploring JupyterLab
tab completion and object attribute completion. Now, let’s explore similar
In the menu bar, go to File , click New , and select Notebook . Choose
Notebook cell
12 TechEngineer.org
JupyterLab tab completion works like IPython. Start typing pr in a notebook
Here’s how to create a sine wave plot using Altair, a library for interactive
the x-axis
2. Calculate sine values: Compute the sine of each x-value for the y-axis
3. Create the plot: Display the data as a line chart to visualize the sine
wave
TechEngineer.org 13
Paste this code into a JupyterLab cell and press Shift + Enter to run it:
alt.Chart(data).transform_calculate(
y='sin(datum.x)'
).mark_line().encode(
x='x:Q',
y='y:Q',
)
Well done! You have taken your first steps in exploring how to run Python code. In
the next module, we’ll explore the features and syntax that make Python a versatile
14 TechEngineer.org