Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Python Dictionary Basics for Network Automation

  • Ferds Tech Channel
  • 2024-11-24
  • 115
Python Dictionary Basics for Network Automation
ciscoccnaccnpccie
  • ok logo

Скачать Python Dictionary Basics for Network Automation бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Python Dictionary Basics for Network Automation или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Python Dictionary Basics for Network Automation бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Python Dictionary Basics for Network Automation

In this video, I talk about some of the standard Python dictionary operations and a couple of useful methods. Below is the code I used in the video:

A Python dictionary is a collection of key-value pairs.
Keys are unique and act as identifiers, while values are associated data.
Dictionaries are mutable, allowing you to modify, add, or delete key-value pairs.
They are widely used for structured data, like configurations or mappings.


Example 0: Creating empty dictionaries
Syntax: dictionary_name = {}
empty_dict1 = {}
print(empty_dict1)

Syntax: dictionary_name = dict()
empty_dict2 = dict() # Using the dict() constructor
print(empty_dict2)

Syntax: dictionary_name = dict.fromkeys(iterable, value)
The 'fromkeys' method creates a new dictionary with keys from the provided iterable
and assigns a default value to each key.
empty_dict3 = dict.fromkeys(["key1", "key2"], None) # Using fromkeys()
print(empty_dict3)


Example 1: Creating a dictionary
Syntax: dictionary_name = {key1: value1, key2: value2, ...}
device = {"hostname": "Router1", "ip": "192.168.1.1", "vendor": "Cisco"}
print(device)

Example 2: Accessing values using keys
Syntax: value = dictionary_name[key] # Direct access using the key
Syntax: value = dictionary_name.get(key, default_value) # Safe access using .get()
print(device["hostname"])
print(device.get("ip"))
print(device.get("model", "Key not found")) # Default value if the key is not found

Example 3: Updating and adding key-value pairs
Syntax: dictionary_name[key] = new_value
device["ip"] = "192.168.1.100" # Update existing value
device["model"] = "ISR 4000" # Add a new key-value pair
print(device)

Example 4: Deleting entries
Syntax: del dictionary_name[key] # Removes key-value pair by key
Syntax: value = dictionary_name.pop(key, default_value) # Removes and retrieves the value
del device["model"] # Delete the 'model' key-value pair
print(device)
removed_value = device.pop("vendor", "Key not found") # Remove 'vendor' key, return default value if the key doesn't exist
print(removed_value)

Example 5: Useful dictionary methods
Syntax: dictionary_name.keys() # Get all keys
Syntax: dictionary_name.values() # Get all values
Syntax: dictionary_name.items() # Get all key-value pairs
print(device.keys()) # List of all keys
print(device.values()) # List of all values
print(device.items()) # List of all key-value pairs

Example 6: Merging dictionaries
Syntax: dictionary_name.update(other_dictionary)
additional_info = {"location": "Data Center", "status": "active"}
device.update(additional_info) # Merge additional_info into device
print(device)

Example 7: Using a dictionary in a Netmiko script
from netmiko import ConnectHandler

Define device information using a dictionary
cisco_device = {
"device_type": "cisco_ios_telnet",
"host": "route-views.routeviews.org",
"username": "rviews",
}

Establish a connection to the device using Netmiko
connection = ConnectHandler(**cisco_device)

Retrieve the hostname of the device
hostname = connection.find_prompt().strip("#")
print(f"Connected to: {hostname}")

Run a command to get the current time on the device
output = connection.send_command("show clock")
print(output)

Disconnect from the device
connection.disconnect()


#python #pythontutorial #networkautomation

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]