-1

I have the following function:

def create_figures():
    circle = figure()
    square = figure()

Then I have the following program:

create_figures()
circle.get_area()

The get_area() method is an error because circle doesn't exist in that scope, so my question is, how do I declare the circle class to be global in a nice pythonian way? I was thinking about declaring it at the top of the program like:

circle = figure()

and then just overwrite it in the create_figures() method.

Luis
  • 127
  • 1
  • 11

1 Answers1

1

Please do correct if I misunderstood your question but is this what you are looking for?

def create_figures():
    circle = figure()
    square = figure()
    return circle,square

And

circle,square = create_figures()
circle.get_area()

Edit: Removed a typo

Julian Chan
  • 446
  • 2
  • 8