What's the difference in Python Nested Function with Variables, and a Class with attributes and methods? I've looked online, asked a programmer, and still haven't figured how a class, is different than a function containing variables and other functions.
Example:
Class
class Add:
def __init__(self):
self.a = 5
self.b = 7
def inside_method(self):
return (self.a + self.b)
add1 = Add()
print('sum is:', add1.inside_method())
Nested function with variables
def func():
a = 5
b = 7
def nested_func():
return (a + b)
return nested_func()
print('sum is:', func())