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

(andrew) #1

Objects are central to Python; in fact, Python really is
just a collection of objects interacting with each other. An
object is self-contained code or data, and the idea of OOP
is to break up a program into smaller, easier-to-
understand components. Up until now, you have mainly
seen procedural programming techniques, which take a
top-down approach and follow predefined sets of
instructions. While this approach works well for simple
programs, to write more sophisticated applications with
better scalability, OOP is often the preferred method
used by professional programmers. However, Python is
very flexible in that you can mix and match these two
approaches as you build applications.


Functions are an important part of the OOP principles of
reusability and object-oriented structure. For the 200-
901 DevNet Associate DEVASC exam, you need to be
able to describe the benefits and techniques used in
Python to build modular programs. Therefore, you need
to know how to use Python classes and methods, which
are covered next.


PYTHON CLASSES


In Python, you use classes to describe objects. Think of a
class as a tool you use to create your own data structures
that contain information about something; you can then
use functions (methods) to perform operations on the
data you describe. A class models how something should
be defined and represents an idea or a blueprint for
creating objects in Python.


Creating a Class


Say that you want to create a class to describe a router.
The first thing you have to do is define it. In Python, you
define a class by using the class keyword, giving the

Free download pdf