Official Cert Guide - Chapter 4 - 5 Flashcards

(71 cards)

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
What is the command for importing modules?
import
26
Which modules are interesting for you code?
The modules without the _ in the library
27
Can you shorten module names?
Yes
28
Which command do you use to import the netmiko module?
from netmiko import ConnectHandler
29
There are several data input types such as data from a website
API or a file. What is the big trick with this data?
30
Which sign is used to start with a new line?
/n
31
Whare are the two requirements with the open() function?
The name of the file you want to work with. The function (e.g. read
32
What are the open functions?
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
How do you close the file?
close()
34
How do you open the file?
open()
35
What happens when you don’t close the file?
File stays open and you might run in a file lock
36
What is the benefit of the with statement instead of only the open statement?
Uses the open() function but doenst require direct assignement to a variable and automatically closes the file when you are ready
37
What are the most common data forms?
1. CSV 2. XML 3. JSON 4. YAML
38
What is the with function benefit?
Display information in an easier way
39
From which data structure is JSON derived?
Java
40
What is the JSON data structure?
Built around key/value pairs that simplify mapping of data and its retrieval
41
What is the nesting capability of JSON?
You start with a main data object
42
What is the convert JSON statement for python lists
JSON Array
43
What is the convert JSON statement for python dictonary?
JSON Objects
44
What are the four functions that you perform to convert JSON data into Python objects and back?
1. load() 2. loads() 3. dump() 4. dumps()
45
Where does the S for refers in load/loads and dump/dumps?
Refers to a string
46
Where stands XML For?
Extensible Markup Language
47
Where is XML most used for?
Configuration automation
48
To which language did XML look like?
HTML. It is developed to work hand-in-hand with HTML for data transport and storage between web-services and APIs
49
Which structure has XML?
Tree structure. With ROOT element on the top
50
Where stands JSON for?
JavaScript Object Notation
51
Which kind of relationship is there between XML elements?
Parent/Child
52
Which model you can use to convert XML into an ordered dictonary in Python?
Module: xmltodict
53
Where stands YAML for?
YAML Ain't Markup Language?
54
What is the big difference between YAML and XML/JSON
Very easy readable. Much simpler syntax/structure
55
On which language is YAML based?
JSON
56
With which sign you can create a list to identify elements?
-
57
What do you need to do to work with Python and YAML?
Import the PyYaml module
58
To which Python state are YAML object converted?
Python dictonaries
59
To which Python state are YAML list converted?
Python lists
60
Which function converts YAML object to python?
yaml.load
61
Which function converts python to YAML objects?
yaml.dump
62
What is used to tell the users what they did wrong and let them try again?
try-except-else-finaly code block
63
What can you do to add error handeling to your code?
use the try statement in the code
64
Where stands TDD for?
Test-Driven Development
65
What is the TDD loop?
1. Write Test 2. Test Fails 3. Write Code 4. Test Passes 5. Refactor
66
What is the benefit of TDD?
That you write code with de goa lin mind
67
Is there a built-in test module in Python?
Yes
68
You need to know how unittest works for DEVASC!
TEST!!!
69
How can you define a function?
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
The name of the function must follow three rules:
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
How do you start working with CSV import to Python?
Code: import csv samplefile = open('routerlist.csv') samplereader = csv.reader(samplefile) sampledata = list(samplereader) sampledata