Python Basics: A Practical Introduction
to Python 3
Python Basics: A Practical Introduction to Python 3
Revised and Updated 4th Edition
David Amos, Dan Bader, Joanna Jablonski, Fletcher Heisler
Copyright © Real Python (realpython.com), 2012–2020
For online information and ordering of this and other books by Real
Python, please visit realpython.com. For more information, please
contact us at email@example.com.
ISBN: 9781775093329 (paperback)
ISBN: 9781775093336 (electronic)
Cover design by Aldren Santos
Additional editing and proofreading by Jacob Schmitt
“Python” and the Python logos are trademarks or registered trade-
marks of the Python Software Foundation, used by Real Python with
permission from the Foundation.
Thank you for downloading this ebook. This ebook is licensed for your
personal enjoyment only. This ebook may not be resold or given away
to other people. If you would like to share this book with another per-
son, please purchase an additional copy for each recipient. If you’re
reading this book and did not purchase it, or if it was not purchased for
your use only, then please return to realpython.com/pybasics-book
and purchase your own copy. Thank you for respecting the hard work
behind this book.
This is a sample from “Python Basics: A Practical
Introduction to Python 3”
With the full version of the book you get a complete Python curriculum
to go all the way from beginner to intermediate-level. Every step along
the way is explained and illustrated with short & clear code samples.
Coding exercises within each chapter and our interactive quizzes help
fast-track your progress and ensure you always know what to focus on
Become a fluent Pythonista and gain programming knowledge you
can apply in the real-world, today:
If you enjoyed the sample chapters you can purchase a full
version of the book at realpython.com/pybasics-book
What Pythonistas Say About Python Basics: A Practical In-
troduction to Python 3
“I love [the book]! The wording is casual, easy to understand, and
makes the information (cid:1088)ow well. I never feel lost in the material, and
it’s not too dense so it’s easy for me to review older chapters over and
I’ve looked at over 10 di(cid:1086)erent Python tutorials/books/online courses,
and I’ve probably learned the most from Real Python!”
— Thomas Wong
“Three years later and I still return to my Real Python books when I
need a quick refresher on usage of vital Python commands.”
— Rob Fowler
“I (cid:1088)oundered for a long time trying to teach myself. I slogged through
dozens of incomplete online tutorials. I snoozed through hours of bor-
ing screencasts. I gave up on countless crufty books from big-time
publishers. And then I found Real Python.
The easy-to-follow, step-by-step instructions break the big concepts
down into bite-sized chunks written in plain English. The authors
never forget their audience and are consistently thorough and detailed
in their explanations. I’m up and running now, but I constantly refer
to the material for guidance.”
— Jared Nielsen
“I love the book because at the end of each particular lesson there are
real world and interesting challenges. I just built a savings estimator
that actually re(cid:1088)ects my savings account – neat!”
— Drew Prescott
“As a practice of what you taught I started building simple scripts for
people on my team to help them in their everyday duties. When my
managers noticed that, I was o(cid:1086)ered a new position as a developer.
I know there is heaps of things to learn and there will be huge chal-
lenges, but I (cid:1087)nally started doing what I really came to like.
Once again: MANY THANKS!”
“What I found great about the Real Python courses compared to others
is how they explain things in the simplest way possible.
A lot of courses, in any discipline really, require the learning of a lot of
jargon when in fact what is being taught could be taught quickly and
succinctly without too much of it. The courses do a very good job of
keeping the examples interesting.”
— Stephen Grady
“After reading the (cid:1087)rst Real Python course I wrote a script to automate
a mundane task at work. What used to take me three to (cid:1087)ve hours now
takes less than ten minutes!”
— Brandon Youngdale
“Honestly, throughout this whole process what I found was just me
looking really hard for things that could maybe be added or improved,
but this tutorial is amazing! You do a wonderful job of explaining and
teaching Python in a way that people like me, a complete novice, could
The (cid:1088)ow of the lessons works perfectly throughout. The exercises truly
helped along the way and you feel very accomplished when you (cid:1087)nish
up the book. I think you have a gift for making Python seem more
attainable to people outside the programming world.
This is something I never thought I would be doing or learning and
with a little push from you I am learning it and I can see that it will be
nothing but bene(cid:1087)cial to me in the future!”
— Shea Klusewicz
“The authors of the courses have NOT forgotten what it is like to be
a beginner – something that many authors do – and assume noth-
ing about their readers, which makes the courses fantastic reads. The
courses are also accompanied by some great videos as well as plenty
of references for extra learning, homework assignments and example
code that you can experiment with and extend.
I really liked that there was always full code examples and each line
of code had good comments so you can see what is doing what.
I now have a number of books on Python and the Real Python ones
are the only ones I have actually (cid:1087)nished cover to cover, and they
are hands down the best on the market. If like me, you’re not a pro-
grammer (I work in online marketing) you’ll (cid:1087)nd these courses to be
like a mentor due to the clear, (cid:1088)u(cid:1086)-free explanations! Highly recom-
— Craig Addyman
About the Authors
At Real Python you’ll learn real-world programming skills from a com-
munity of professional Pythonistas from all around the world.
The realpython.com website launched in 2012 and currently helps
more than three million Python developers each month with free
programming tutorials and in-depth learning resources.
Everyone who worked on this book is a practitioner with several years
of professional experience in the software industry. Here are the mem-
bers of the Real Python tutorial team who worked on Python Basics:
David Amos is the content technical lead for Real Python. After leav-
ing academia in 2015, David worked in various technical positions as
a programmer and data scientist. In 2019, David joined Real Python
full time to pursue his passion for education. He lead the charge on
rewriting and updating the Python Basics curriculum to Python 3.
Dan Bader is the owner and editor in chief of Real Python and the
main developer of the realpython.com learning platform. Dan has
been writing code for more than twenty years and holds a master’s
degree in computer science. He’s the author of Python Tricks, a best-
selling programming book for intermediate Python developers.
Joanna Jablonski is the executive editor of Real Python. She likes
natural languages just as much as she likes programming languages.
Her love for puzzles, patterns, and pesky little details led her to follow
a career in translation. It was only a matter of time before she would
fall in love with a new language: Python! She joined Real Python in
2018 and has been helping Pythonistas level up ever since.
Fletcher Heisler is the founder of Hunter2, where he teaches de-
velopers how to hack and secure modern web apps. As one of the
founding members of Real Python, Fletcher wrote the ﬁrst version of
the Python curriculum this book is based on in 2012.