Python Scripting for Network Engineers: Realizing Network Automation for Reliable Networks by Hassan Wajid
Author:Hassan, Wajid [Hassan, Wajid]
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2019-05-27T16:00:00+00:00
Chapter 6 Functions in Python Scripting
6.1 Objectives
The main objectives of this chapter are to discuss:
• Functions, Constructs and its Uses
• Built-in and User Defined Functions
• Discusses Object Oriented Programming
• Discusses Classes and its usage
6.2 Introduction
Python is a general-purpose high-level programming language. Like any other programming language, Python has some codes that are used more than once and hence need not to be rewritten over and over. This chapter discusses how the Python script can be modularized and made repeatable. These repeatable codes are called Functions.
Functions, Object Oriented Programming and Classes are discussed in this chapter that are used extensively in Python Scripts for writing large scripts which can handle many input requests, interrupts and generate kind of actions with changing conditions of the inputs and requirements.
The main objectives of this chapter include; being able to understand why and how programmers divide programs up into sets of cooperating functions, to be able to define new functions in Python and lastly to understand the details of function calls and parameter passing in Python.
6.2.1 Functions
Python has some pieces for code that have been organized into a block and can be reused more than once for a single related function. These blocks of codes are the ones referred to as functions of Python. They provide high-levels of reusing program codes and hence enhancing modularity in the program development process. Creating a customized function is easy in Python.
Code for creating a function
Figure 6-1 Code demonstration of creating a function
Figure 6-2 output in python
Functions in Python begin with the key-word def which is then followed by the name of the function and parenthesis. The parenthesis takes all the input parameters and the code block in every function begins with a colon. The return statement is used to exit any function and can be called in any other part of the program.
6.2.2 Object-oriented programming
Python is known to be a language. This is because almost everything is in Python is written in terms of objects which are associated with properties and methods.
6.2.3 Classes
Classes in Python are like object constructors and is created with the keyword class. Code for creating a class in python
Figure 6-3 Code demonstration of creating a function
Figure 6-4 Code output in python
Figure 6-5 Code representing how to create a class in Python
The use of functions and objects in Python programming makes it easy to design a functional code with full functionalities and be easily understandable (Ozer, 2017). Functions increase modularity in program codes and hence make them easy to be reused. This chapter mainly focuses on the programming using Python functions and classes that makes Python termed as an object-oriented programming language.
6.3 Program Components in Python
Python language has several components. These components include; numbers, strings, sets, lists, dictionaries, tuples and functions (Rivers & Koedinger, 2017). All these components work together in meeting the specifications of a given program code. Python combines its components in one program hence ensuring that a fully functional program which meets the needs of the users is designed in the process.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Eco-friendly approach of bio-indigo synthesis and developing purification methods towards isolation of indigo from indirubin and bacterial fragments by Ramalingam Manivannan & Kaliyan Prabakaran & Young-A Son(157402)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74277)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(66080)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(65828)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(65266)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50860)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(40219)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(40190)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(40055)
What's Done in Darkness by Kayla Perrin(27104)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26484)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26435)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(21017)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20775)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20648)
The Fifty Shades Trilogy & Grey by E L James(19605)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19487)
Shot Through the Heart by Mercy Celeste(19349)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17492)