python code question - what is this line in my code doing and why?

this chunk of code is coming from a book and the book doesn't explain it and i am not getting it. The line start, stop=0, start has the result of switching the values for start and stop. But I don't understand why that is happening.

def interval(start, stop=None, step=1):
    print('start ' + str(start))
    print('stop ' + str(stop))
    print('step ' + str(step))
    print('*****')
    if stop is None:
        start, stop = 0, start
        print('start ' + str(start))
        print('stop ' + str(stop))
        print('step ' + str(step))

print(interval(10))

OUTPUT:
start 10
stop None
step 1
*****
start 0
stop 10
step 1
alexmac05Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Stephen CalabreseCommented:
def interval(start, stop=None, step=1): assigns the default value of stop variable to be None and the step varaible to be 1.

 if stop is None:
        start, stop = 0, start
        print('start ' + str(start))
        print('stop ' + str(stop))
        print('step ' + str(step))

Open in new window

assigns start to 0. Then stop gets assigned to the old value of start which is 10.
alexmac05Author Commented:
I do not understand this line.

start, stop = 0, start

what is this syntax? why is this setting start = 10?

I can understand stop = 0 but what are the two starts doing there? I can see the effect is that start = 10 but I don't understand how that happens.
alexmac05Author Commented:
why is this shuffling the parameters?

start, stop = 0, start # shuffle the parameters
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

alexmac05Author Commented:
I think I found the answer on stack overflow. reading it now

http://stackoverflow.com/questions/18165296/shuffling-parameters
alexmac05Author Commented:
the stackoverflow link explains it:

example:
x,y = a,b means x=a and y=b

so in the case of the above example:
start, stop = 0, start

start = 0 and stop = start

I found it by finally googling for 'shuffling parameters python' but it isn't an easy problem to define for search engines because if you knew it was a multiple assignment, then you would have understood it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alexmac05Author Commented:
tags for this question:
shuffling parameters python
multiple assignment
Magnus Lie Hetland Python for Beginners
chapter 5
alexmac05Author Commented:
the solution was found by me on stackoverflow but the problem is hard to find in search engines so we should leave this for others.

I'm going to add some more tags
shuffling parameters python
multiple assignment
Magnus Lie Hetland Python for Beginners
chapter 5
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.