Yearly Archive: 2020

Regular Expressions

Summary : http://www.patrickdenis.biz/blog/regular-expressions-special-characters-and-patterns/ . Matches any single character, including white space. * Matches 0 or more sequences of the pattern. + Matches 1 or more sequences of the pattern. ? Matches 0 or 1 occurrences of the pattern. ^ Matches the beginning of…
Read more

Set

Set are like Dictionary but without key value pair, there are just element, if you convert a list to a a set it will remove all duplicate. ipv4 = [‘10.10.10.1’, ‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3, ‘10.10.10.3, ‘10.10.10.2, ‘10.10.10.2] set(ipv4) {‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3…
Read more

Dictionary Methods

device = {} device[‘ip_addr’] = ‘10.10.10.1’ print(device) {‘ip_addr’: ‘10.10.10.1’} dir(device) will list all method available To loop over a dictionary you can do it by key or key value or both : for key in device: ….print(key) for value in…
Read more

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’