DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1

You can add another variable named sw1 and instantiate
the Switch class just as you did the Router class, by
passing in attributes. If you create another print
statement using the newly created sw1 object, you see
the output shown in Example 4-3.


Example 4-3 Code Results of Using Class Inheritance

Click here to view code image


Rtr1
Router Model :iosV
Software Version :15.6.7
Router Management Address:10.10.10.1
Rtr2
Router Model :isr4221
Software Version :16.9.5
Router Management Address:10.10.10.5
Sw1
Switch Model :Cat9300
Software Version :16.9.5
Switch Management Address:10.10.10.8

To learn more about classes, methods, and inheritance,
you can refer to the Python documentation.
https://docs.python.org/3/tutorial/classes.html


WORKING WITH PYTHON MODULES


A central goal of OOP is to allow you to build modular
software that breaks code up into smaller, easier-to-
understand pieces. One big file with thousands of lines of
code would be extremely difficult to maintain and work
with. If you are going to break up your code into
functions and classes, you can also separate that code
into smaller chunks that hold key structures and classes

Free download pdf