Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pass integer by reference in Python

# when you want to pass immutable data types as references in Python, return multiple instead
def RectToPolar(x, y):
    r = (x ** 2 + y ** 2) ** 0.5
    theta = math.atan2(y, x)
    return r, theta # return 2 things at once

r, theta = RectToPolar(3, 4) # assign 2 things at once
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pass #integer #reference #Python
ADD COMMENT
Topic
Name
9+1 =