0

I know, it's a noob question..

I have these variables:

pgwdth = 30;  
mrgn = 0;  
fmt = True  

And this function:

def Param(x,pgwdth,mrgn,fmt):
    parametros = x.split(" ")
    if parametros[0][1] == "p":
    numerozinho = int(parametros[1])
        print "Changing pgwdth"
        pgwdth += numerozinho
        print pgwdth
    elif parametros[0][1] == "m":
        numerozinho = int(parametros[1])
        print "Changing mrgn"
        mrgn += numerozinho
        print mrgn
    elif parametros[0][1] == "f":
        numerozinho = parametros[1]
        print "On/Off"
        if numerozinho == "on\n":
            fmt = True
        elif numerozinho == "off\n":
            fmt = False
        else:
            "Error"
        print fmt
    else:
    print "Error"   

I just want it to return the variables that it used as arguments after changing it.

1
  • 2
    return x,pgwdth,mrgn,fmt as the last statement. Commented Feb 27, 2013 at 11:05

2 Answers 2

3
return x,pgwdth,mrgn,fmt

Simple as that.

And where you call it:

val1,val2,val3,val = Param(x,pgwdth,mrgn,fmt)
Sign up to request clarification or add additional context in comments.

Comments

3

A function returns exactly one result. The trick is to make that result a tuple containing the multiple values.

return (x, pgwdth, mrgn, fmt)

In Python syntax the braces around the tuple are optional so you'll more often see

return x, pgwdth, mrgn, fmt

Which looks like returning multiple values, but now it's clear there is really just one return value

1 Comment

Little quirks like that make Python harder to read, but more interesting to code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.