PYTHON TUTORIAL: FUNCTION FOR BEGINNERS // NETWORK ENGINEERS

Veröffentlicht am: 02 Juni 2024
auf dem Kanal: Ferds the NetDev
164
3

Python functions for beginners // network engineers

1. Basic Function Creation
def show_connection():
print("Connecting to network device.")

show_connection()

2. Functions with Parameters
Example 1:
def connect_to_device(device_ip):
print(f"Connecting to device {device_ip}.")

connect_to_device("10.10.10.1")

Example 2:
def show_device_info(device_ip, vlan):
print(f"Device {device_ip} is using VLAN {vlan}.")

show_device_info(vlan=10,device_ip="10.10.10.1")

3. Functions with Return Values
def get_http_status_text(http_code):
if http_code == 200:
return "OK"
elif http_code == 404:
return "Not Found"
elif http_code == 500:
return "Internal Server Error"
else:
return "Unknown"

print(get_http_status_text(500))


4. More Examples
Example 1: Using individual variables
device_1 = "SW1"
device_2 = "SW2"

def show_connection(device_name):
print(f"Connecting to {device_name} is in progress.")
print("Connection successful.")

show_connection(device_1)
show_connection(device_2)

Example 2: Using a list of devices
list_switches = ["SW1", "SW2", "SW3"]

def show_connection(device_name):
print(f"Connecting to {device_name} is in progress.")
print("Connection successful.")

for switch in list_switches:
show_connection(switch)


#python #devnet #devops


Auf dieser Seite können Sie das Online-Video PYTHON TUTORIAL: FUNCTION FOR BEGINNERS // NETWORK ENGINEERS mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Ferds the NetDev 02 Juni 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 164 Mal angesehen und es wurde von 3 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!