Monthly Archive: July 2020

For Loops

There is two type of loop in Python, For loops and While Loops. For Loops ips = [“10.10.10.1”, “10.10.10.2”, “10.10.10.3”, “10.10.10.4”] for each_ip in ips: ….print(each_ip) 10.10.10.1 10.10.10.2 10.10.10.3 10.10.10.4 Another example : devices = [“device1”, “device2”] for each_host in…
Read more

Booleans

Example of a Boolean : variable = ‘whaterver’ if expression ==<>!= statement else ‘whatever2’ or if expression ==<>!= statement: ….variable = ‘whaterver’ else: ….variable = ‘whatever2’  

Split() & Join()

Example of how to use split : ip_Addr = “10.10.10.1” ip_Addr.split(“.”) <— will create a list [“10”, “10”, “10”, “1”] octect = ip_Addr.spit(“.”) octect[0] 10 Example of how to use join : “.”.join(octect) print(octect) 10.10.10.1

List Slices

While opening a file as an example. while open(“ext.ext”, “r”) as f: ….output = f.readlines() ….len(output) ….print(output[0:5]) This would create a list and 1 element per lines The Len would be the total of element in the list The output…
Read more

Lists

Creating a list in Python my_list = [ ] type(my_list) my_list = [‘haha’, ‘100’, 100, 2.0] To access element from a list you can choose each of them starting by element 0 my_list[0] haha my_list[3] 2.0 To change an element…
Read more