PYTHON TUTORIAL: FUNCTION FOR BEGINNERS // NETWORK ENGINEERS

Pubblicato il: 02 giugno 2024
sul canale di: 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


In questa pagina del sito puoi guardare il video online PYTHON TUTORIAL: FUNCTION FOR BEGINNERS // NETWORK ENGINEERS della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Ferds the NetDev 02 giugno 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 164 volte e gli è piaciuto 3 spettatori. Buona visione!