Range arguments

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715887

    Comments posted to this topic are about the item Range arguments

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71401

    Nice question, thanks Steve
    Python basics 101...

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • HappyGeek

    SSCoach

    Points: 18666

    Lol, knew answer and still selected the wrong one! Eyes, coffee! Good question thanks Steve.

    ...

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715887

    I thought this was fun. I keep stopping to think about how it works, so good reminder for me as well.

  • Shayn Thomas

    SSCertifiable

    Points: 5411

    nice question steve,
    thanks

    ---------------------------------------------------------------------------------------
    The more you know, the more you know that you dont know

  • gary.rumble

    SSCommitted

    Points: 1710

    <pedant>
    Based on the example, only the first argument is optional because the default increment is 1.
    </pedant>

  • dawryn

    SSCarpal Tunnel

    Points: 4469

    There is no correct answer possible!
    You have no chance to give only the second argument to any function without giving the first one.
    There are two forms of function prototype:
    - one of them is with one argument only;
    - the other is with three arguments (the last one has default value defined that is the only one that is optional).

  • radu.popa 78500

    SSC Rookie

    Points: 26

    So, if the 1st arg is optional, how does one call this function to pass the 2nd and 3rd args?

    To me, only the 3rd arg is truly optional. This seems to be confirmed by the function signature definition on the link provided in the question:
    range(start, stop[, step])

    I can see how Python allows passing just one arg and infer that refers to stop.
    Nevertheless, the 1st arg (start) seems "semi-optional" at best.

  • Jeff Moden

    SSC Guru

    Points: 994667

    radu.popa 78500 - Friday, December 14, 2018 9:26 AM

    So, if the 1st arg is optional, how does one call this function to pass the 2nd and 3rd args?

    To me, only the 3rd arg is truly optional. This seems to be confirmed by the function signature definition on the link provided in the question:
    range(start, stop[, step])

    I can see how Python allows passing just one arg and infer that refers to stop.
    Nevertheless, the 1st arg (start) seems "semi-optional" at best.

    That was my impression, as well.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems
    Create a Tally Function (fnTally)

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715887

    The first argument is optional in that if you pass in one argument, it is for the second parameter. If you pass two, then the first is the first parameter and the second is the second parameter. If you pass three, they are used in their positions.

    I think this is strange, but the first argument is optional.

  • dawryn

    SSCarpal Tunnel

    Points: 4469

    Steve Jones - SSC Editor - Wednesday, December 19, 2018 1:49 PM

    The first argument is optional in that if you pass in one argument, it is for the second parameter. If you pass two, then the first is the first parameter and the second is the second parameter. If you pass three, they are used in their positions.

    I think this is strange, but the first argument is optional.

    If the first argument were optional function declaration would look like:

    range([start, ]stop[, step])


    but there are two distinct function declarations (see answer Ref:) with the same name and totally different scope of arguments (commonly used in C/C++, ...):

    range(stop)
    range(start, stop[, step])


    It might be misinterpreted as a single function with first argument optional.

  • radu.popa 78500

    SSC Rookie

    Points: 26

    Yes, an overloaded function with two implementations.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply