Part 1: Introduction to Python

Part 1 is now called “Python Basics: A Practical Introduction to Python 3” and it is a free upgrade for you and this is the version of the book you should be working with. We’ve updated the lessons to use Python 3.9, rewrote many parts of the book entirely, and added additional bonus resources such as online quizzes and new exercises.

Download Book Files

You can access this book in different file formats that are optimized to give you a great reading experience, no matter which device you are using. The options are as follows:

DRM-free PDF optimized for reading on tablets and computers:

Download

Python Basics (PDF)

5.8 MB

ePub version for e-reader devices and phones/tablets:

Download

Python Basics (ePub)

3.8 MB

Mobipocket (.mobi) version for reading on Kindle devices:

Changelog

2020-10-05

  • Hooray, we’re officially ending the Early Access phase!
  • Major updates and edits throughout the book
  • Full proofreading pass
  • Updated to Python 3.9

2020-05-18

  • Fixed ePub code blocks on Apple Books (iPad and macOS 10.15)
  • Formatting fixes and cleanups
  • Proofread chapters 1–4, 14, 16

2020-03-28

  • Clean up resource links
  • Formatting fixes and cleanups
  • Clean up long lines of code bleeding into the page margins

2020-02-25

  • Updated images to show Python 3.8 instead of Python 3.7
  • Chapter 2:
    • Added note about installing multiple Python versions
    • Added some page breaks and other formatting fixes
  • Chapter 8:
    • Explained why .lower() is used to compare strings in sport example
    • Converted players scores to integers in sport example
    • Added parentheses in compound logical expressions to make them clearer
    • Explained how assignment statements work with compound logical expressions where assignment operator = and equality comparator == appear in the same statement
    • Removed an extra coin flip in Challenge 8.9 Solution C that didn’t affect the final result but was inconsistent with the problem statement. Also cleaned up the solution and added docstrings and comments.
    • Fixed bug in Challenge 8.9 Solution B by replacing undefined num_trials variables with NUM_TRIALS
  • Chapter 9
    • Fixed a typo in Challenge 9.5 saying to choose 3 prepositions when it should be 2
    • Cleaned-up the solution to Challenge 9.5
  • Typo fixes

2020-02-14:

  • Update book for Python 3.8
  • Update book cover

2020-02-11:

  • Added new Modules and Packages chapter with exercises and a new quiz
  • Replaced monospace keyboard shortcuts with fancy formatting
  • Replaced italicized menu shortcuts with fancy formatting

2020-02-04:

  • Updated the File Input and Output chapter to focus on pathlib; added new challenges
  • Revamped the PDF chapter, including a discussion of concatenating and merging PDF files; added new challenges
  • Updated the pip chapter based on editorial feedback; replaced pip install with python3 -m pip install
  • Added a brief discussion of list comprehensions to the Tuples, Lists, and Dictionaries chapter; added new exercise
  • Typo fixes and formatting cleanup

2019-11-15:

  • Revamped GUI chapter
  • Typo fixes, cleanups

Bonus Materials

You can access the bonus material, such as quizzes, exercise solutions, and code challenges at the following URL:

realpython.com/python-basics/resources/

This is your “hub” for accessing all of the book materials, so be sure to check it out. Of course you’ll also find the relevant exercises and quizzes at the end of each section in the book. But the resources page linked above is where you can find it all in one spot.

Happy Pythoning!

FAQ

How will I receive updates?

You’ll always find the latest version available for download here on realpython.com.

How do I access the book bonus material (exercises, quizzes, …)?

The first chapter in the book contains links to the bonus materials—an online learning path, coding exercises and challenges, and interactive quizzes to check your learning progress.

How can I give feedback on the book?

Please use this link to share your feedback: realpython.com/python-basics/feedback

We welcome any and all feedback or suggestions for improvement you may have.

Please feel free to be as terse or detailed as you see fit. All feedback is stored anonymously, but you can choose to leave your name and contact information so we can follow up or mention you on our “Thank You” page.

Thank you for helping us make this book an even more valuable learning resource for the Python community.

asyhariachmadichsan on Jan. 9, 2020

Hi, thank you for creating such amazing product!

I just purchased and downloaded the 3 e-book files and skimmed through it. And I saw the Django version used throughout the course is 1.10. Do you have any planning to update Part 2 and Part 3 of the course?

Thank You!

Regards,

Ichsan

Dan Bader RP Team on Jan. 9, 2020

Hi Ichsan, we’re planning to release updates for part 2 and 3 of the course at some point once the final version of part 1 (Python Basics) has been completed :)

Andreas on May 11, 2020

Just quick UI/UX Feedback. I was trying to bookmark this page, and was getting frustrated when I noticed the “Mark Completed” and the “Bookmark action” are right next to each other - which made be believe that hitting the “Bookmark” would cause this to be marked completed. That make sense? I think the “bookmark” and “marked completed” should be separated by whitespace .... just my $0.02

pchegoor on July 24, 2020

When will the FINAL version of this Ebook release?

Ernie White on Sept. 17, 2020

On page 17 is the following code:

import requests
resp = requests.get("http://olympus.realpython.com") 
html = resp.text
print(html[86:132])

Running that code I get the following

Traceback (most recent call last):
  File "hello.py", line 2, in <module>
    resp = requests.get("http://olympus.realpython.com")
  File "/Users/user/python-course/env/lib/python3.8/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/user/python-course/env/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/user/python-course/env/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/user/python-course/env/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/Users/user/python-course/env/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='olympus.realpython.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd17dc711c0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))

Bartosz Zaczyński RP Team on Sept. 17, 2020

Python can’t make a network connection to a non-existent resource. It might have existed in the past, or maybe it was used as an imaginary example.

Anyway, if you copy and paste that URL to your web browser’s address bar, it’ll tell you that this site can’t be reached.

You can also try to ping the hostname from the terminal to confirm:

$ ping olympus.realpython.com
ping: olympus.realpython.com: Name or service not known

In other words, there’s no known IP address behind such a domain name.

Dan Bader RP Team on Sept. 17, 2020

The correct URL for the Mount Olympus example should be olympus.realpython.org (.org instead of .com)

Dan Bader RP Team on Sept. 17, 2020

Aaand we just corrected it in the book as well, thanks! :)

eawongtheprogrammer on Oct. 6, 2020

Congratulations on leaving early access for book 1, Python Basics.

I saw that there are real examples updated in book 1 after version 3.9 release

Sample Projects and Code Challenges showing you how to build fun & rewarding example projects using your newfound Python skills. All challenges and exercises come with full sample (solution) code so you can check your own implementation against them. Here are some of the Python projects you’ll build: Stock investment tracker

I would like to jump straight to Stock investment tracker, where can I find it in the book?

Dom on Feb. 8, 2021

Hi, I am not sure if this is the correct place to ask.

I am currently going through Part 1: Introduction to Python. In Challenge 9.4, there seems to be an error with the median() function. The computation for the median for when the number of items is odd seems to be wrong. Can I confirm this?

You must own this product to join the conversation.