Official Cert Guide - Chapter 4 - 5 Flashcards

1
Q

Question

A

Answer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a python function?

A

A named block of code that can take wide variety parameters and return some form of output back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can you reuse a function?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where stands OOPS for?

A

Object Oriented Programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

As what kind of modern language was Python Developed?

A

Object Oriented Programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Object Oriented Programming?

A

A computer programming paradigm that makes it possible to describe real-world things and their relationships to each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does OOP do?

A

You can create an object with several variables anywhere in your code and call this OOP function when you want.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Python in relation with OOP?

A

Object are central in Python. Python is jus a collection of objects interacting with each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the idea of OOP?

A

Break up a program into smaller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an important part of the OOP principles of reusability and object oriented structure?

A

Functions!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you describe objects in Python

A

With Classes!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are classes?

A

A class is a tool you use to ceate your own data structure that contains information about something.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you use classes

A

You can use functions(methods) to perform operations on the data you describe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When you start with a class what is the first thing to do?

A

You need to pass some values to get started. The first values is always: self

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens with the self value?

A

The self value passes the object name that you select to instantiate the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

You can start the fucntion with init. How do we call this?

A

dunder or magic methods. This will setup the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The attributes you add to the class how are these called and what are they doing?

A

Called method. This become actions that you can perform on the object you are creating.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is recommanded to do when you are creating a class

A

Provide other capitalizing signs from a variable. Example: use ‘'’test’’’ for a class and ‘‘test’’ for a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What do you replace when you use inheritance

A

You can replace methods and attributes that need to be different

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is important when you inherit in a class

A

You create the class before the colon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a central goal of OOP?

A

Allow you to build modular software that break code up into smaller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How can you separate code into smaller chunks that hold key structures and classes with movement between each other?

A

This can be done with import statement. You import modules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Creating modular code provides the following benefits?

A
  1. Easier readability/maintainability
  2. Low coupling/high cohesion
  3. Code reusability
  4. Collaboration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Which module types are there?

A
  1. Third party modules imported in Python library
  2. Hand made appending with a .py extenion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is the command for importing modules?

A

import

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Which modules are interesting for you code?

A

The modules without the _ in the library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Can you shorten module names?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Which command do you use to import the netmiko module?

A

from netmiko import ConnectHandler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

There are several data input types such as data from a website

A

API or a file. What is the big trick with this data?

30
Q

Which sign is used to start with a new line?

A

/n

31
Q

Whare are the two requirements with the open() function?

A

The name of the file you want to work with. The function (e.g. read

32
Q

What are the open functions?

A
  1. r: open for reading (default)
  2. w: open for writing
  3. x: open for exclusive creation
  4. a: open for writing
  5. b: open in binary mode
  6. t: open in text mode(default)
  7. +: open for updating (reading and writing)
33
Q

How do you close the file?

A

close()

34
Q

How do you open the file?

A

open()

35
Q

What happens when you don’t close the file?

A

File stays open and you might run in a file lock

36
Q

What is the benefit of the with statement instead of only the open statement?

A

Uses the open() function but doenst require direct assignement to a variable and automatically closes the file when you are ready

37
Q

What are the most common data forms?

A
  1. CSV
  2. XML
  3. JSON
  4. YAML
38
Q

What is the with function benefit?

A

Display information in an easier way

39
Q

From which data structure is JSON derived?

A

Java

40
Q

What is the JSON data structure?

A

Built around key/value pairs that simplify mapping of data and its retrieval

41
Q

What is the nesting capability of JSON?

A

You start with a main data object

42
Q

What is the convert JSON statement for python lists

A

JSON Array

43
Q

What is the convert JSON statement for python dictonary?

A

JSON Objects

44
Q

What are the four functions that you perform to convert JSON data into Python objects and back?

A
  1. load()
  2. loads()
  3. dump()
  4. dumps()
45
Q

Where does the S for refers in load/loads and dump/dumps?

A

Refers to a string

46
Q

Where stands XML For?

A

Extensible Markup Language

47
Q

Where is XML most used for?

A

Configuration automation

48
Q

To which language did XML look like?

A

HTML. It is developed to work hand-in-hand with HTML for data transport and storage between web-services and APIs

49
Q

Which structure has XML?

A

Tree structure. With ROOT element on the top

50
Q

Where stands JSON for?

A

JavaScript Object Notation

51
Q

Which kind of relationship is there between XML elements?

A

Parent/Child

52
Q

Which model you can use to convert XML into an ordered dictonary in Python?

A

Module: xmltodict

53
Q

Where stands YAML for?

A

YAML Ain’t Markup Language?

54
Q

What is the big difference between YAML and XML/JSON

A

Very easy readable. Much simpler syntax/structure

55
Q

On which language is YAML based?

A

JSON

56
Q

With which sign you can create a list to identify elements?

A

-

57
Q

What do you need to do to work with Python and YAML?

A

Import the PyYaml module

58
Q

To which Python state are YAML object converted?

A

Python dictonaries

59
Q

To which Python state are YAML list converted?

A

Python lists

60
Q

Which function converts YAML object to python?

A

yaml.load

61
Q

Which function converts python to YAML objects?

A

yaml.dump

62
Q

What is used to tell the users what they did wrong and let them try again?

A

try-except-else-finaly code block

63
Q

What can you do to add error handeling to your code?

A

use the try statement in the code

64
Q

Where stands TDD for?

A

Test-Driven Development

65
Q

What is the TDD loop?

A
  1. Write Test
  2. Test Fails
  3. Write Code
  4. Test Passes
  5. Refactor
66
Q

What is the benefit of TDD?

A

That you write code with de goa lin mind

67
Q

Is there a built-in test module in Python?

A

Yes

68
Q

You need to know how unittest works for DEVASC!

A

TEST!!!

69
Q

How can you define a function?

A
  1. Use the keyword def
  2. A name for the function
  3. A set of parentheses enclosing any arguments you want to pass to the function
  4. And a colon at the end
70
Q

The name of the function must follow three rules:

A
  1. Must not start with a number
  2. Must not be a reserved Python word (print(), input(), etc)
    3 Can ben any combination of the: A-Z, a-z, 0-9, _, -
71
Q

How do you start working with CSV import to Python?

A

Code:
import csv
samplefile = open(‘routerlist.csv’)
samplereader = csv.reader(samplefile)
sampledata = list(samplereader)
sampledata