Interpret basic Python components and scripts

📘CCNP Encore (350-401-ENCORE-v1.1)


1. Why Python Is in the CCNP ENCOR Exam

Cisco includes Python in the ENCOR exam because:

  • Modern networks are programmable
  • Network devices support APIs and automation
  • Python is widely used to:
    • Automate configuration
    • Collect device data
    • Validate network states
    • Interact with controllers (like Cisco DNA Center)

👉 You are NOT expected to be a Python developer
👉 You ARE expected to read and understand basic Python scripts

The keyword in the exam blueprint is “Interpret”, not “Write complex code”.


2. What a Python Script Is

A Python script is a text file that contains Python commands and ends with:

.py

Example:

backup_config.py
check_interfaces.py

A Python script:

  • Is executed line by line
  • Runs from top to bottom
  • Stops if it hits an error (unless handled)

In networking, scripts are used to:

  • Read device information
  • Send commands
  • Process outputs
  • Make decisions automatically

3. Basic Python Syntax Rules (Exam Important)

3.1 Indentation (Very Important)

Python uses indentation to define blocks of code.

Example:

if status == "up":
    print("Interface is up")
  • Spaces at the beginning of the line matter
  • Usually 4 spaces
  • No curly braces { } like other languages

❗ Wrong indentation = script fails


3.2 Comments

Comments explain the code and are ignored when running.

Single-line comment:

# This script checks device status

Comments are useful for:

  • Documentation
  • Understanding scripts in exams

4. Variables

A variable stores data in memory.

Example:

hostname = "Router1"
  • No need to declare data type
  • Python decides automatically

Common variable naming rules:

  • Letters, numbers, underscores
  • Cannot start with a number
  • Case-sensitive

Example:

device_ip = "192.168.1.1"

5. Data Types (Exam Critical)

5.1 String (Text)

Text values are strings.

device_name = "Switch1"
  • Enclosed in quotes
  • Used for:
    • Hostnames
    • IP addresses
    • Commands

5.2 Integer (Whole Numbers)

port = 22

Used for:

  • VLAN IDs
  • Port numbers
  • Counters

5.3 Float (Decimal Numbers)

cpu_usage = 12.5

Used for:

  • Percentages
  • Timers
  • Measurements

5.4 Boolean (True or False)

status = True

Used for:

  • Conditions
  • Validation
  • Decision-making

6. Lists

A list stores multiple values in one variable.

devices = ["Router1", "Router2", "Switch1"]
  • Ordered
  • Index starts at 0

Access items:

devices[0]

Lists are used for:

  • Device inventories
  • Interface lists
  • IP address collections

7. Dictionaries (Very Important for Networking)

A dictionary stores data as key-value pairs.

device = {
    "hostname": "Router1",
    "ip": "192.168.1.1",
    "os": "IOS-XE"
}

Access value:

device["ip"]

Used heavily in:

  • API responses
  • JSON data
  • Network configurations

8. Operators

8.1 Assignment Operator

x = 10

8.2 Comparison Operators

Used in conditions.

OperatorMeaning
==Equal
!=Not equal
>Greater than
<Less than

Example:

if cpu > 80:
    print("High CPU")

8.3 Logical Operators

OperatorMeaning
andBoth conditions true
orOne condition true
notReverse condition

Example:

if status == "up" and admin == "enabled":

9. Conditional Statements (if, elif, else)

Used to make decisions.

if status == "up":
    print("Interface is operational")
elif status == "down":
    print("Interface is down")
else:
    print("Unknown state")

Used for:

  • Checking interface state
  • Validating configuration
  • Handling errors

10. Loops

Loops repeat actions.


10.1 for Loop

Used when you know how many times to repeat.

for device in devices:
    print(device)

Used for:

  • Looping through devices
  • Checking interfaces
  • Applying configuration

10.2 while Loop

Runs while a condition is true.

while attempts < 3:
    attempts += 1

Used for:

  • Retry logic
  • Waiting for responses

11. Functions

A function is reusable code.

def check_status():
    print("Checking status")

Call function:

check_status()

Functions help:

  • Organize code
  • Avoid repetition
  • Improve readability

12. Input and Output

12.1 Printing Output

print("Configuration applied")

Used to:

  • Show results
  • Display messages
  • Debug scripts

12.2 User Input

ip = input("Enter IP address: ")

Input is always a string.


13. Importing Modules

Modules add extra functionality.

import json

Or:

from datetime import datetime

In networking:

  • json → API data
  • requests → REST APIs
  • time → delays

You don’t need to know deep module usage—just recognize imports.


14. Error Handling (try / except)

Used to prevent script crashes.

try:
    print(int("abc"))
except:
    print("Error occurred")

Used for:

  • API failures
  • Connection issues
  • Invalid input

15. Reading and Interpreting a Python Script (Exam Skill)

You should be able to:

  • Identify variables
  • Understand loops
  • Predict output
  • Identify errors
  • Understand logic flow

Example:

devices = ["R1", "R2"]

for d in devices:
    print(d)

Output:

R1
R2

16. Python and Networking Context (Exam Relevant)

Python is used with:

  • REST APIs
  • Controllers
  • Automation frameworks
  • Device configuration tools

You do not need to:

  • Write full automation scripts
  • Memorize libraries
  • Build applications

You must:

  • Understand script structure
  • Interpret logic
  • Read code confidently

17. Exam Key Takeaways (Very Important)

✔ Understand basic Python syntax
✔ Know variables and data types
✔ Understand lists and dictionaries
✔ Read loops and conditions
✔ Interpret simple scripts
✔ Understand Python’s role in network automation


18. Simple Summary

Python in CCNP ENCOR is about understanding, not programming expertise.


Buy Me a Coffee