Python Basics Flashcards

1
Q

Reasons to use Python

A

Interpreted scripting language

Used to write various types of Python apps

Low barrier to entry

Exists on most Linux distributions, including NX-OS

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

Python Helper Functions

A

help()
Returns the python built-in documentation about the object

dir()
Returns the attributes (and methods) of the object or module

type()
Returns the type of the object

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

Python Readability Tips

A

Here are a few things to consider when writing Python to achieve readability and uniformity:

Single-line comments: When creating a single line comment, simply begin the line with the hash (#) character and the comment automatically terminates at the end of the line.

Multiline comments: When multiline comments (comments that span multiple lines) are needed, use a delimiter (unique character not in the comment itself) to define the beginning and end of the comment.

Whitespace: Characters used for spacing, that is, spaces and tabs.

Indentation (spaces versus tabs): Leading whitespace at the beginning of the line that helps determine the grouping of statements.

The Python Style Guide (PEP8): A list of coding conventions for the Python code.

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

Common Python Data Types

A

Strings
Sequences of character data

Numbers
Integers, allowing for mathematical operation to be performed directly in code

Lists
Containers used to store multiple data at the same time

Dictionaries
Use key value pairs to match keys to their value

Booleans
Values and operators used in code

Files
Objects used by Python

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

SNMP Requests

A

SNMP uses a get-request to retrieve a MIB variable from the SNMP agent (a network device).

SNMP uses a set-request to set variables that are stored in the MIB.

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

YANG

A

Yet Another Next Generation (YANG) is a data modeling language that the IETF defined in 2016 in RFC 7950. The YANG concepts focus heavily on networking infrastructure and networking constructs. YANG describes what can be configured and monitored on a device, and the administrative actions that can be executed on a device.

The YANG language has the following attributes:

Easy to read and to learn

Hierarchical configuration of data models

Reusable types and groupings (structured types)

Extensibility through augmentation

Formal constraints for configuration validation

Data modularity through modules and submodules

Well-defined versioning rules

Some aspects of the YANG language to note are the following:

Every data model is a module, a self-contained top-level hierarchy of nodes.

Data types can be imported from another YANG module or defined within a module.

YANG uses containers to group related nodes.

It uses lists to identify nodes that are stored in a sequence.

Each individual attribute of a node is represented by a leaf.

Every leaf must have an associated type.

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