...

/

Instantiating Classes

Instantiating Classes

We'll cover the following...

Instantiating classes in Python is straightforward. To instantiate a class, simply call the class as if it were a function, passing the arguments that the __init__() method requires. The return value will be the newly created object.

Press + to interact
import fibonacci2
fib = fibonacci2.Fib(100) #①
print (fib) #②
#<fibonacci2.Fib object at 0x7f7594e75ba8>
print (fib.__class__) #③
#<class 'fibonacci2.Fib'>
print (fib.__doc__ ) #④
#iterator that yields numbers in the Fibonacci sequence

① You are creating ...