Python Foundations for Network Engineers Flashcards

1
Q

list characteristics of Python 2.x

A
  • No longer developed, but supported by community
  • Better library support
  • Default on Linux and Mac
  • Supported by Cisco NX-OS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

list characteristics of Python 3.x

A
  • Under active development
  • Easier to learn (note: design goal)
  • Fixed major issues in 2.x
  • Not backwards compatible
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

why shebang is needed

A

!/usr/bin/env python is needed in Linux and Mac for the script to execute on a correct program path

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

returns documentation about the object

A

.help()

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

returns the attributes and methods the object or module has

A

.dir()

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

returns the type of the object

A

.type()

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

what the python style guide is called

A

PEP8

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

what pythonic means

A

idiomatic python, which is concerced about readability and uniformity

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

what means strings are immutable

A

individual characters cannot be modified after the string has been created

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

how to print an empty line in Python

A

“\n”

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

what is concatenation

A

adding multiple strings together

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

list built-in methods for strings

A
  • .upper() and .lower()
  • .replace()
  • .startswith()
  • .format()
  • .split()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to refer to the last element in a list

A

sample_list[-1]

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

what are the common built-in methods for lists

A
.append()
.pop()
.insert()
.count()
.extend()
.sort()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is the item of a dictionary called

A

key-value pair

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

what are the common built-in methods for dictionaries

A

.pop()
.update()
.get()

17
Q

the difference between while and for loops

A

while loop until a conditional is matched, for loops over a limited range of items such as list items

18
Q

when should you deploy functions

A

when a block of code is used more than once in a script

19
Q

how to read and open a file for Python script

A

f = open(“config.txt”, “r”)