Python Forum
in which 2.x version was // first used?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
in which 2.x version was // first used?
#1
i see that // (floordiv) is used in 2.7.12. for lots of things the documentation says in which version it was first used or defined. i don't see it for //. so i am curious if // was in Python all along or if it was added at some point, and if the latter, at which version it was added.

i see that for the numbers i picked, in version 2.7.12, both / and // always give me the same result. does this mean // was added to 2.7.12 to make the transition to Python3 easier?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
PEP-238 Implementation
python 2.2
(Oct-09-2018, 07:11 PM)Skaperen Wrote: in version 2.7.12, both / and // always give me the same result
that is expected as / in python2 is floor division (i.e. same as //) for int
EDIT: added for int to make it clear. tnx, nilamo
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
They're not the same in python2 for floats, only for ints. In python 2, int / int = int, but in python 3, they wanted to make sure information wasn't lost (and lots of people were confused about why the decimal wasn't in the results).
Reply
#4
(Oct-09-2018, 08:09 PM)buran Wrote: that is expected as / in python2 is floor division (i.e. same as //) for int
EDIT: added for int to make it clear. tnx, nilamo
since 2.7.12 supported // and since i believed it was intended to be for transitioning to Python3 i believed / would be the same as in python3. i believed so strongly that i didn't even test it before wondering how it might affect what i was coding today and wonder how older python2 would have this effect.

i had coded a test for version 2 and earlier to use / else use // to get the floor division behavior. now i know that code will be fine on all python2 and python3.

this code is not yet tested:
def intsize(a):
    try:
        n = int(a,0)
    except:
        n = int(a)
    if bytes == str:
        return (len(hex(n))-1)/2
    else:
        return (len(hex(n))-1)//2
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020