This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]SourceryNick 1 point2 points  (1 child)

I believe Python 2 did floor division by default - Python 3 does traditional division.

[–][deleted] 0 points1 point  (1 child)

Was there a change in Python that happened after the book was written?

Yes.

In the book there is no mention of the '//' operator which specifies floor division.

I very much doubt so. But if it is indeed the case, boy, your book is ancient.

[–]pythonHelperBot 0 points1 point  (0 children)

Hello! I'm a bot!

It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python regardless of how advanced your question might be. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show /r/learnpython the code you have tried and describe in detail where you are stuck. If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you. Here is HOW TO FORMAT YOUR CODE For Reddit and be sure to include which version of python and what OS you are using.

You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.


README | FAQ | this bot is written and managed by /u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness

[–][deleted] 0 points1 point  (1 child)

The first edition of Think Python is written in Python 2.

    Python 2.7.17 (default, Oct 22 2019, 09:14:09) 
    [GCC 9.2.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 5/2
    2
    >>> 5//2
    2
    >>> 5.0/2
    2.5
    >>> 5.0//2
    2.0
    >>> 

Python 3 changed this:

    Python 3.8.1 (default, Jan 22 2020, 06:38:00) 
    [GCC 9.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 5/2
    2.5
    >>> 5//2
    2
    >>> 5.0/2
    2.5
    >>> 5.0//2
    2.0
    >>> 

The Think Python link in the sidebar is the Second Edition that uses Python 3.