tag:blogger.com,1999:blog-68804927694706670992020-03-29T09:50:01.860+05:30Networking Fundamentals and Certification BlogThis blog is about CCNA, CCNP, CCIE, Software Testing, Scripting and Networking Technologies.Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.comBlogger461125tag:blogger.com,1999:blog-6880492769470667099.post-77362196512664465042018-02-16T23:10:00.000+05:302018-02-16T23:10:55.160+05:30How DNS work<div dir="ltr" style="text-align: left;" trbidi="on">Step 1. The browser sends a query to the local DNS server in your network.<br /><br />Step 2. If the local network has no internal DNS server or the DNS server has no information about the site you want to visit, a query is sent to the recursive DNS server of your Internet service provider (ISP). If the recursive server has information about the IP address in its cache, your browser receives that information. No additional queries are performed.<br /><br />Step 3. However, if the recursive server does not know the IP address, the recursive server sends the query to one of the 13 sets of root name servers located worldwide. A root server knows the DNS information about a top-level domain (TLD).<br /><br />Step 4. The DNS server of a TLD sends information about the second-level domain and its authoritative name server. An authoritative name server knows all the addressing information for a particular domain.<br /><br />Step 5. The authoritative name server responds to a query by returning the Address Record (A record) to your ISP. The ISP’s recursive server stores the record on its cache for a specific amount of time and sends the IP address to your browser.</div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com0tag:blogger.com,1999:blog-6880492769470667099.post-90266292574445882752017-12-15T10:55:00.000+05:302018-09-20T12:51:39.714+05:30Python OOP Concepts<div dir="ltr" style="text-align: left;" trbidi="on"><b>Variable concept:</b><br /><br />a = 10<br />a is a variable that refers to object 10.<br />same is for function definition<br />def test<br />a test is a variable which refers to object function test<br />variable is reference or label to object not placeholder<br />All attributes are called by "." operator<br />Anything defined inside class is class attributes<br />Anything defined inside function is variable<br />only variable has scope<br />every class should be instantiated<br /><br />while True is a substitution of do-while in python<br /><br /># only variable have scope but attribute doesn’t have<br />## variable defined under class are class attributes. variable defined inside and outside functions are local and global variables<br />## list and dictionary don’t store data. They refer to data<br />## variables are not object in python. variables are reference to object<br />## all definition happens in run time<br />## any object ref count is 0 is freed from memory i.e. garbage collection<br />## you can’t have two scope under a function at a same time<br />## import this (for python zen)<br />## python is compiled interpreter language not line by line interpreter language<br />## i ++ is not supported in python<br />## to check object is callable or not<br />&gt;&gt;&gt; v = 10<br />&gt;&gt;&gt; callable(v)<br />False<br />&gt;&gt;&gt; def foo(): print("hello world")<br />...<br />&gt;&gt;&gt; callable(foo)<br />True<br />## class is a instance of type<br /><br />## tuple is ", separator operator<br /><br />&gt;&gt;&gt; t = 1,2,3,4,5,6<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; t<br />(1, 2, 3, 4, 5, 6)<br /><br />or<br /><br />&gt;&gt;&gt; t = (1,2,3,4,5)<br />&gt;&gt;&gt; t<br />(1, 2, 3, 4, 5)<br /><br />## we can’t have one element tuple<br />&gt;&gt;&gt; t = (1)&nbsp; ## this is basically integer<br />&gt;&gt;&gt; t<br />1<br />&gt;&gt;&gt; type(t)<br /><class int=""></class><br />&gt;&gt;&gt;<br /><br />If you want to have one element tuple use<br />&gt;&gt;&gt; t = (1,)<br />&gt;&gt;&gt; t<br />(1,)<br />&gt;&gt;&gt; type(t)<br /><class tuple=""></class><br /><br /><b>dict:</b><br />&gt;&gt;&gt; d = { 'one': 1, 'two': 2, 'three': 3}<br />&gt;&gt;&gt; d<br />{'one': 1, 'two': 2, 'three': 3}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d = dict(one = 1, two = 2, three = 3)<br />&gt;&gt;&gt; d<br />{'one': 1, 'two': 2, 'three': 3}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; type(d)<br /><class dict=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x = dict(four = 4, five =5, six = 6)<br />&gt;&gt;&gt; x<br />{'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d = dict(one = 1, two = 2, three =3, **x)<br />&gt;&gt;&gt; d<br />{'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; 'four' in x<br />True<br />&gt;&gt;&gt; 'three' in x<br />False<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; for k in d: print(k)<br />...<br />one<br />two<br />three<br />four<br />five<br />six<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; for k, v in d.items():print(k, v)<br />...<br />one 1<br />two 2<br />three 3<br />four 4<br />five 5<br />six 6<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d['three']<br />3<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x['three']<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />KeyError: 'three'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x.get('three')<br />&gt;&gt;&gt; x<br />{'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d.get('three')<br />3<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x.get('three', 'not found')<br />'not found'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x<br />{'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; del x['four']<br />&gt;&gt;&gt; x<br />{'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x.pop('five')<br />5<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x<br />{'six': 6}<br />&gt;&gt;&gt;<br /><br />## iter function is a function that returns iterator object<br />## Note: yield turns function into generator. Each time yield is run it returns<br />## the value and next time the function is called, execution starts right after yield and this turns function into generator<br />## and what it generates is iterator object which can be used like any iterator object in python.<br /><br /># define a list<br />my_list = [4, 7, 0, 3]<br /><br /># get an iterator using iter()<br />my_iter = iter(my_list)<br /><br />## iterate through it using next()<br /><br />#prints 4<br />print(next(my_iter))<br /><br />#prints 7<br />print(next(my_iter))<br /><br />## next(obj) is same as obj.__next__()<br /><br />#prints 0<br />print(my_iter.__next__())<br /><br />#prints 3<br />print(my_iter.__next__())<br /><br />## This will raise error, no items left<br />next(my_iter)<br /><br />two ways to create dict in python:<br />&gt;&gt;&gt; d = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}<br />&gt;&gt;&gt; for k in d:<br />...&nbsp; &nbsp; &nbsp;print(k, d[k])<br />...<br />one 1<br />two 2<br />three 3<br />four 4<br />five 5<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; for k in sorted(d.keys()):<br />...&nbsp; &nbsp; &nbsp;print(k,d[k])<br />...<br />five 5<br />four 4<br />one 1<br />three 3<br />two 2<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d = dict(<br />...&nbsp; &nbsp; &nbsp;one =1, two = 2, three = 3, four =4, five = 'five'<br />... )<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; for k in sorted(d.keys()):<br />...&nbsp; &nbsp; &nbsp;print(k,d[k])<br />...<br />five five<br />four 4<br />one 1<br />three 3<br />two 2<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d['seven'] = 7<br />&gt;&gt;&gt; for k in sorted(d.keys()):<br />...&nbsp; &nbsp; &nbsp;print(k, d[k])<br />...<br />five five<br />four 4<br />one 1<br />seven 7<br />three 3<br />two 2<br /><br />&gt;&gt;&gt; d = { 'one': 1, 'two': 2, 'three': 3}<br />&gt;&gt;&gt; d<br />{'one': 1, 'two': 2, 'three': 3}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d = dict(one = 1, two = 2, three = 3)<br />&gt;&gt;&gt; d<br />{'one': 1, 'two': 2, 'three': 3}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; type(d)<br /><class dict=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x = dict(four = 4, five =5, six = 6)<br />&gt;&gt;&gt; x<br />{'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d = dict(one = 1, two = 2, three =3, **x)<br />&gt;&gt;&gt; d<br />{'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; 'four' in x<br />True<br />&gt;&gt;&gt; 'three' in x<br />False<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; for k in d: print(k)<br />...<br />one<br />two<br />three<br />four<br />five<br />six<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; for k, v in d.items():print(k, v)<br />...<br />one 1<br />two 2<br />three 3<br />four 4<br />five 5<br />six 6<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d['three']<br />3<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x['three']<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />KeyError: 'three'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x.get('three')<br />&gt;&gt;&gt; x<br />{'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d.get('three')<br />3<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x.get('three', 'not found')<br />'not found'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x<br />{'four': 4, 'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; del x['four']<br />&gt;&gt;&gt; x<br />{'five': 5, 'six': 6}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x.pop('five')<br />5<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x<br />{'six': 6}<br />&gt;&gt;&gt;<br /><br />In python NOT has first precedence, then AND then OR<br /><br /># define a list<br />my_list = [4, 7, 0, 3]<br /><br /># get an iterator using iter()<br />my_iter = iter(my_list)<br /><br />## iterate through it using next()<br /><br />#prints 4<br />print(next(my_iter))<br /><br />#prints 7<br />print(next(my_iter))<br /><br />## next(obj) is same as obj.__next__()<br /><br />#prints 0<br />print(my_iter.__next__())<br /><br />#prints 3<br />print(my_iter.__next__())<br /><br />## This will raise error, no items left<br />next(my_iter)<br /><br />### for is used for deterministic loop<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/Python_OOP$ python3 -v findall_exercise.py<br />## for verbose print<br /><br />## Instance of base class is type and inheritance of base class is object<br /><br />Iterator in Python is simply an object that can be iterated upon. An object which will return data, one element at a time.<br />Technically speaking, Python iterator object must implement two special methods, __iter__() and __next__(), collectively called the iterator protocol.<br />An object is called iterable if we can get an iterator from it. Most of the built-in containers in Python like: list, tuple, string etc. are iterable.<br />The iter() function (which in turn calls the __iter__() method) returns an iterator from them.<br /><br />The match() function only checks if the RE matches at the beginning of the string while search() will scan forward through the string for a match. It’s important to keep this distinction in mind. Remember, match() will only report a successful match which will start at 0; if the match wouldn’t start at zero, match() will not report it.<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; print(re.match('super', 'superstition').span())<br />(0, 5)<br />&gt;&gt;&gt; print(re.match('super', 'insuperable'))<br />None<br />On the other hand, search() will scan forward through the string, reporting the first match it finds.<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; print(re.search('super', 'superstition').span())<br />(0, 5)<br />&gt;&gt;&gt; print(re.search('super', 'insuperable').span())<br />(2, 7)<br /><br />&gt;&gt;&gt; a = dict(one=1, two=2, three=3)<br />&gt;&gt;&gt; b = {'one': 1, 'two': 2, 'three': 3}<br />&gt;&gt;&gt; c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))<br />&gt;&gt;&gt; d = dict([('two', 2), ('one', 1), ('three', 3)])<br />&gt;&gt;&gt; e = dict({'three': 3, 'one': 1, 'two': 2})<br />&gt;&gt;&gt; a == b == c == d == e<br />True<br /><br />To print python builtins:<br />&gt;&gt;&gt; dir(__builtins__)<br /><br />&gt;&gt;&gt; list(range(5,3))<br />[]<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; 'ab c\n\nde fg\rkl\r\n'.splitlines()<br />['ab c', '', 'de fg', 'kl']<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; 'ab c\n\nde fg\rkl\r\n'.split()<br />['ab', 'c', 'de', 'fg', 'kl']<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; "One line\n".splitlines()<br />['One line']<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; 'Two lines\n'.split('\n')<br />['Two lines', '']<br />&gt;&gt;&gt;<br /><br />## default inheritance of all class is from object<br />that’s in python3<br /><br />python2<br />class Employee(object): pass<br /><br />python3<br />class Employee(): pass<br /><br />## class attributes are commonly shared among all instances and automatically inherited to their instances. Instances can overwrite them<br /><br />##if we make a callable method as class attribute, they are automatically wired up as&nbsp;an instance method<br />## for instance method to work, the first argument should be always referenced to the instance<br /><br />## all functions defined under __init__ are local variables<br />if we want them globally we can create instance attribute<br />all instance attributes are visible globally<br /><br />## this will not work<br />&gt;&gt;&gt; class Car:<br />...&nbsp; &nbsp; &nbsp;def __init__(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("car object created...")<br />...&nbsp; &nbsp; &nbsp;def drive():<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("driving a car....")<br />...<br />&gt;&gt;&gt; c = Car()<br />car object created...<br />&gt;&gt;&gt; c.drive()<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />TypeError: drive() takes 0 positional arguments but 1 was given<br />&gt;&gt;&gt;<br /><br />c.drive() is equivalent to Car.drive(c)<br /><br />but Car.drive() will work in python3.<br />&gt;&gt;&gt; Car.drive()<br />driving a car....<br /><br />To make it work in both pyhon2 and python3, we can use staticmethod<br /><br />calling drive either from object or from class should work. But this is not at all good practice to follow<br />&gt;&gt;&gt; class Car:<br />...&nbsp; &nbsp; &nbsp;def __init__(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("car object created...")<br />...&nbsp; &nbsp; &nbsp;@staticmethod<br />...&nbsp; &nbsp; &nbsp;def drive():<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("driving a car....")<br />...<br />&gt;&gt;&gt; c = Car()<br />car object created...<br />&gt;&gt;&gt; c.drive()<br />driving a car....<br />&gt;&gt;&gt; Car.drive()<br />driving a car....<br />&gt;&gt;&gt;<br /><br />Other decorator is @classmethod<br /><br />## without classmethod decorator<br /><br />&gt;&gt;&gt; class Car:<br />...&nbsp; &nbsp; &nbsp;def __init__(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("car object created...")<br />...&nbsp; &nbsp; &nbsp;@staticmethod<br />...&nbsp; &nbsp; &nbsp;def drive():<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("driving a car....")<br />...&nbsp; &nbsp; &nbsp;def sell(c):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("c =", c)<br />...<br /><br />&gt;&gt;&gt; c = Car()<br />car object created...<br />&gt;&gt;&gt; c.drive()<br />driving a car....<br />&gt;&gt;&gt; c.sell()<br />c = <__main__ .car="" 0x108c30d30="" at="" object=""></__main__><br />## sell takes objet instance<br /><br />Now let’s use @classmethod<br /><br />&gt;&gt;&gt; class Car:<br />...&nbsp; &nbsp; &nbsp;def __init__(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("car object created...")<br />...&nbsp; &nbsp; &nbsp;@staticmethod<br />...&nbsp; &nbsp; &nbsp;def drive():<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("driving a car....")<br />...&nbsp; &nbsp; &nbsp;@classmethod<br />...&nbsp; &nbsp; &nbsp;def sell(c):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("c =", c)<br />...<br />&gt;&gt;&gt; c = Car()<br />car object created...<br />&gt;&gt;&gt; c.drive()<br />driving a car....<br />&gt;&gt;&gt; Car.drive()<br />driving a car....<br />&gt;&gt;&gt; c.sell()<br />c = <class main__.car=""></class><br />## it will always pass class as an argument to this particular instance<br />c.sell() or Car.sell() means the same<br />&gt;&gt;&gt; Car.sell()<br />c = <class main__.car=""></class><br /><br />staticmethod will pass nothing it will call function as it is. a static method cannot access neither class or instance attributes.<br /><br />## trying to find value in dictionary with unknown key will raise a error<br /><br />&gt;&gt;&gt; a = {"name": "john", "role": "admin"}<br />&gt;&gt;&gt; a<br />{'name': 'john', 'role': 'admin'}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a["name"]<br />'john'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a["city"]<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />KeyError: 'city'<br /><br />## if we don’t want to raise an error. we can use get function. it will return default value None for unknown key<br /><br />&gt;&gt;&gt; a.get("name")<br />'john'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a.get("city")<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; v = a.get("city")<br />&gt;&gt;&gt; print(v)<br />None<br />&gt;&gt;&gt;<br /><br />## instead of default value None we can also decide what value to print<br /><br />&gt;&gt;&gt; v = a.get("city", "not found")<br />&gt;&gt;&gt; v<br />'not found'<br />&gt;&gt;&gt;<br /><br />but<br /><br />&gt;&gt;&gt; a.get("role", "not found")<br />'admin'<br />&gt;&gt;&gt;<br /><br />run script in debugger mode + python prompt<br />Python_OOP$ python3 -m pdb scope_1.py<br />&gt; /Users/nawlekha/Desktop/pyATS/Python_OOP/scope_1.py(10)<module>()</module><br />-&gt; """<br />(Pdb) help<br /><br />Documented commands (type help <topic>):</topic><br />========================================<br />EOF&nbsp; &nbsp; c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d&nbsp; &nbsp; &nbsp; &nbsp; h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;list&nbsp; &nbsp; &nbsp; q&nbsp; &nbsp; &nbsp; &nbsp; rv&nbsp; &nbsp; &nbsp; &nbsp;undisplay<br />a&nbsp; &nbsp; &nbsp; cl&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;debug&nbsp; &nbsp; help&nbsp; &nbsp; &nbsp; ll&nbsp; &nbsp; &nbsp; &nbsp; quit&nbsp; &nbsp; &nbsp;s&nbsp; &nbsp; &nbsp; &nbsp; unt<br />alias&nbsp; clear&nbsp; &nbsp; &nbsp; disable&nbsp; ignore&nbsp; &nbsp; longlist&nbsp; r&nbsp; &nbsp; &nbsp; &nbsp; source&nbsp; &nbsp;until<br />args&nbsp; &nbsp;commands&nbsp; &nbsp;display&nbsp; interact&nbsp; n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;restart&nbsp; step&nbsp; &nbsp; &nbsp;up<br />b&nbsp; &nbsp; &nbsp; condition&nbsp; down&nbsp; &nbsp; &nbsp;j&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;next&nbsp; &nbsp; &nbsp; return&nbsp; &nbsp;tbreak&nbsp; &nbsp;w<br />break&nbsp; cont&nbsp; &nbsp; &nbsp; &nbsp;enable&nbsp; &nbsp;jump&nbsp; &nbsp; &nbsp; p&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retval&nbsp; &nbsp;u&nbsp; &nbsp; &nbsp; &nbsp; whatis<br />bt&nbsp; &nbsp; &nbsp;continue&nbsp; &nbsp;exit&nbsp; &nbsp; &nbsp;l&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pp&nbsp; &nbsp; &nbsp; &nbsp; run&nbsp; &nbsp; &nbsp; unalias&nbsp; where<br /><br />Miscellaneous help topics:<br />==========================<br />exec&nbsp; pdb<br /><br />(Pdb) n<br />&gt;Python_OOP/scope_1.py(113)<module>()</module><br />-&gt; """<br />(Pdb) s<br /><br />l == list a program<br />n = next will step over a function<br />s = will step into a function<br />globals = to list all global variables currently defined<br /><br /><br />function prototype:<br />==================<br /><br />&gt;&gt;&gt; def greet():<br />...&nbsp; &nbsp; &nbsp;print("Hello world")<br />...<br />&gt;&gt;&gt; def greet(name):<br />...&nbsp; &nbsp; &nbsp;print("Welcome", name)<br />...<br />&gt;&gt;&gt; greet("John")<br />Welcome John<br />&gt;&gt;&gt; greet()<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />TypeError: greet() missing 1 required positional argument: 'name'<br />&gt;&gt;&gt;<br /><br />Rem: the last definition overwrites the previous definition<br />similar to<br />a = 10<br />a = “hello world”<br /><br />Both greet variable points to different functions and last overwrites the previous<br /><br />So how to do polymorphism<br />=============<br />a function with an ability to work differently based on different arguments.<br /><br />&gt;&gt;&gt; def greet(name=None):<br />...&nbsp; &nbsp; &nbsp;if name is None:<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("Hello world")<br />...&nbsp; &nbsp; &nbsp;else:<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print("Welcome", name)<br />...<br />&gt;&gt;&gt; greet("John")<br />Welcome John<br />&gt;&gt;&gt; greet()<br />Hello world<br /><br />or<br /><br />&gt;&gt;&gt; def greet(name="Guest"):<br />...&nbsp; &nbsp; &nbsp;print("Welcome", name)<br />...<br />&gt;&gt;&gt; greet("John")<br />Welcome John<br />&gt;&gt;&gt; greet()<br />Welcome Guest<br /><br /><br />## we should always pass non-default argument followed by default argument<br />&gt;&gt;&gt; def greet(name="Guest", city):<br />...&nbsp; &nbsp; &nbsp;print("Hello", name, "Welcome to", city)<br />...<br />&nbsp; File "<stdin>", line 1</stdin><br />SyntaxError: non-default argument follows default argument<br />&gt;&gt;&gt;<br /><br /><br />&gt;&gt;&gt; def greet(name, city="bangalore"):<br />...&nbsp; &nbsp; &nbsp;print("Hello", name, "Welcome to", city)<br />...<br />&gt;&gt;&gt; greet("John", "Mumbai")<br />Hello John Welcome to Mumbai<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; greet("John")<br />Hello John Welcome to bangalore<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; def greet(name="Guest", city="bangalore"):<br />...&nbsp; &nbsp; &nbsp;print("hello", name, "Welcome to", city)<br />...<br />&gt;&gt;&gt; greet()<br />hello Guest Welcome to bangalore<br />&gt;&gt;&gt;<br /><br />## print takes care of adding space after “,” and add new line after last argument<br /><br />&gt;&gt;&gt; def greet(name="Guest", city="bangalore"):<br />...&nbsp; &nbsp; &nbsp;print("hello", name, "Welcome to", city)<br />...<br />&gt;&gt;&gt; greet("John")<br />hello John Welcome to bangalore<br /><br />&gt;&gt;&gt; greet("Mumbai")<br />hello Mumbai Welcome to bangalore<br />## python doesn’t know Mumbai is name of city. It just replace first argument with Mumbai<br /><br />&gt;&gt;&gt; greet(city="Mumbai")<br />hello Guest Welcome to Mumbai<br />## this is what we call as passing key-word argument<br /><br />## solution is explicitly mention keyword arguments<br />&gt;&gt;&gt; greet(city="Pune", name="Smith")<br />hello Smith Welcome to Pune<br /><br />## all python programs can be run as the script or loaded as a module.<br />## if you run a program as a script, name of a file is __main__ and everything in the file will execute including the main function.<br />## if you load program as a module, codes outside of “if” statement will only execute i.e. program main function will not run.<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop$ vi test.py<br />def greet(): print("Hello world")<br />name = "John"<br /><br />print("__name__=", __name__)<br /><br />if __name__ == "__main__":<br />&nbsp; &nbsp; &nbsp; &nbsp; greet()<br />&nbsp; &nbsp; &nbsp; &nbsp; print("name=", name)<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop$ python3 test.py<br />__name__= __main__<br />Hello world<br />name= John<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop$ python3<br />Python 3.6.2 |Anaconda, Inc.| (default, Sep 21 2017, 18:29:43)<br />[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import test<br />__name__= test<br />&gt;&gt;&gt; test.greet()<br />Hello world<br />&gt;&gt;&gt; test.name<br />'John'<br />&gt;&gt;&gt;<br /><br />## string is a sequence and immutable. Other sequences in python are list and tuples.<br />All sequence should be indicible<br /><br />## to have mutable string we can use bytearray<br /><br />&gt;&gt;&gt; a = "Hello world"<br />&gt;&gt;&gt; a<br />'Hello world'<br />&gt;&gt;&gt; a[0]<br />'H'<br />&gt;&gt;&gt; a[0] = "A"<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />TypeError: 'str' object does not support item assignment<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a = bytearray(b"Hello world")<br />&gt;&gt;&gt; a<br />bytearray(b'Hello world')<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a[0]<br />72 ## this is ascii value of H<br />&gt;&gt;&gt; a[0] = 65<br />&gt;&gt;&gt; a<br />bytearray(b'Aello world') ## this mutates existing string<br />&gt;&gt;&gt;<br /><br />## Two kinds of immutable strings. Unicode and byte string<br />Strings by default represent sequence of unicode characters<br />&gt;&gt;&gt; a = "hello world"<br />&gt;&gt;&gt; type(a)<br /><class str=""></class><br />&gt;&gt;&gt;<br />In unicode, each character can be of different bytes may be 1, 2 or 3 byte size based on encoding.This supports different language characters and it is UTF compliance.This is useful to read textual data.<br /><br />but to read binary data i.e. packet, binary buffer, element must be byte.Each element must be a byte.<br />to create byte string<br /><br />&gt;&gt;&gt; b = b"Hello world"<br />&gt;&gt;&gt; b<br />b'Hello world'<br />&gt;&gt;&gt; type(b)<br /><class bytes=""></class><br />&gt;&gt;&gt; print(b)<br />b'Hello world'<br />## this is a sequence of bytes<br /><br />## byte array can only be created from byte string.<br /><br />## Variable argument function. Function that can take one or more arguments<br />## arbitrary argument list a.k.a varargs<br /><br />&gt;&gt;&gt; def greet(*args):<br />...&nbsp; &nbsp; &nbsp;pass<br /><br />or<br /><br />&gt;&gt;&gt; def greet(*users):<br />...&nbsp; &nbsp; &nbsp;pass<br /><br />## args is not a keyword. Non of the function parameters are keywords. self is also not a reserved keyword. args and kwargs are just a convention.<br /><br />* followed by name indicates collect all arguments in the form of tuple<br /><br />&gt;&gt;&gt; def greet(*users):<br />...&nbsp; &nbsp; &nbsp;print("users=", users)<br />...<br />&gt;&gt;&gt; greet("John", "smith", "Sam", "Joe")<br />users= ('John', 'smith', 'Sam', 'Joe') ## this is tuple<br /><br />&gt;&gt;&gt; def greet(name, city="Pune", *visited):<br />...&nbsp; &nbsp; &nbsp;print(name)<br />...&nbsp; &nbsp; &nbsp;print(city)<br />...&nbsp; &nbsp; &nbsp;print(visited)<br />...<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; greet()<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />TypeError: greet() missing 1 required positional argument: 'name'<br />&gt;&gt;&gt; greet("John")<br />John<br />Pune<br />()<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; greet("John", "bengaluru", "Kolkatta", "Chennai", "Mumbai")<br />John<br />bengaluru<br />('Kolkatta', 'Chennai', 'Mumbai')<br /><br />## so rule is no-defualt, followed by default followed by varargs. This is for python2<br />but here limitation is we can’t print default value.if we use default argument with varargs, the default argument is no longer a default<br /><br />but in python3 we can have non-default followed by varargs and default<br /><br /><br />&gt;&gt;&gt; def greet(name, *visited, city="Pune"):<br />...&nbsp; &nbsp; &nbsp;print(name)<br />...&nbsp; &nbsp; &nbsp;print(city)<br />...&nbsp; &nbsp; &nbsp;print(visited)<br />...<br />&gt;&gt;&gt; greet("John")<br />John<br />Pune<br />()<br />&gt;&gt;&gt; greet("John", "Mumbai", "Kolkatta", 'Hyderabad') ## default argument always remain default<br /><br />John<br />Pune<br />('Mumbai', 'Kolkatta', 'Hyderabad')<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; greet("John", "Mumbai", "Kolkatta", 'Hyderabad', city= "Bengaluru") ## now overwrite default value<br />John<br />Bengaluru<br />('Mumbai', 'Kolkatta', 'Hyderabad')<br /><br />## so in python3.4 and above non-default should be the first argument always and varargs and default arguments are interchangeable<br /><br />## How to pass variable number of arguments<br /><br />&gt;&gt;&gt; def store_record(name, role, dept, city):<br />...&nbsp; &nbsp; &nbsp;print("Storing name = {}, role= {}, dept = {}, city= {}".format(name, role, dept,city))<br />...<br />&gt;&gt;&gt; rec = "John", "Support", "IT", "Bengaluru"<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; store_record(*rec)<br />Storing name = John, role= Support, dept = IT, city= Bengaluru<br /><br />## numbers of arguments in function and numbers of values in tuple used while calling should be same<br /><br />&gt;&gt;&gt; rec = "John", "Support", "IT"<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; store_record(*rec)<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />TypeError: store_record() missing 1 required positional argument: 'city'<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; rec = "John", "Support", "IT", "Mumbai", "Bengaluru" ## this can be either list or tuple<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; store_record(*rec)<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />TypeError: store_record() takes 4 positional arguments but 5 were given<br /><br /><br />## tuple is extension of list<br /><br />## Advantage of format<br />&gt;&gt;&gt; a = "Hello %s, How are you %s, What will you do today %s"<br />&gt;&gt;&gt; a<br />'Hello %s, How are you %s, What will you do today %s'<br />&gt;&gt;&gt; print(a % ("John", "John", "John"))<br />Hello John, How are you John, What will you do today John<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; b = "Hello {0}, How are you {0}, What will do you today {0}"<br />&gt;&gt;&gt; b.format("John")<br />'Hello John, How are you John, What will do you today John'<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; a = "Decimal: {0:d}, Hex: {0:x}, Oct: {0:o}, Bin: {0:b}"<br />&gt;&gt;&gt; a<br />'Decimal: {0:d}, Hex: {0:x}, Oct: {0:o}, Bin: {0:b}'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a.format(34)<br />'Decimal: 34, Hex: 22, Oct: 42, Bin: 100010'<br />&gt;&gt;&gt;<br /><br />{0:d} == %d<br />{0:x} == %x<br /><br />&gt;&gt;&gt; def store_data(*n): ## collects arguments as tuple<br />...&nbsp; &nbsp; &nbsp;print(n)<br />...<br />&gt;&gt;&gt; store_data()<br />() ## empty tuple<br />&gt;&gt;&gt;<br /><br />arbitrary keyword arguments<br />&gt;&gt;&gt; def store_data(**n): ## collects arguments as dictionary<br />...&nbsp; &nbsp; &nbsp;print(n)<br />...<br />&gt;&gt;&gt; store_data()<br />{} ## empty dictionary<br /><br />&gt;&gt;&gt; store_data(name="John", a=100, test="Helloworld", info=(10,20,30))<br />{'name': 'John', 'a': 100, 'test': 'Helloworld', 'info': (10, 20, 30)}<br /><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; def store_data(a, b=20, *c, **d):<br />...&nbsp; &nbsp; &nbsp;print("a=", a)<br />...&nbsp; &nbsp; &nbsp;print("b=", b)<br />...&nbsp; &nbsp; &nbsp;print("c=", c)<br />...&nbsp; &nbsp; &nbsp;print("d=", d)<br />...<br />&gt;&gt;&gt; store_data(10)<br />a= 10<br />b= 20<br />c= ()<br />d= {}<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; store_data(10,20,30,40,50,60,70)<br />a= 10<br />b= 20<br />c= (30, 40, 50, 60, 70)<br />d= {}<br />&gt;&gt;&gt;<br /><br />## all positional arguments got collected in tuple<br /><br />&gt;&gt;&gt; store_data(10,20,30,40,50,60,70, x=10, name= "Sam", role= "Admin")<br />a= 10<br />b= 20<br />c= (30, 40, 50, 60, 70)<br />d= {'x': 10, 'name': 'Sam', 'role': 'Admin'}<br /><br />## all keyword arguments got collected in dictionary<br /><br />&gt;&gt;&gt; def store_record(name, role, dept, city):<br />...&nbsp; &nbsp; &nbsp;print("Storing name = {}, role = {}, dept = {}, city = {}".format(name, role, dept, city))<br />...<br />&gt;&gt;&gt; rec = {"name": "John", "dept": "IT", "city": "Bengaluru", "role": "Support"}<br /><br />&gt;&gt;&gt; store_record(**rec)<br />Storing name = John, role = Support, dept = IT, city = Bengaluru<br /><br />## when using ** whatever variables you are passing there should be a mapping<br /><br /><br />## for default value<br />&gt;&gt;&gt; def store_record(name, role, dept, city="Pune"):<br />...&nbsp; &nbsp; &nbsp;print("Storing name = {}, role = {}, dept = {}, city = {}".format(name, role, dept, city))<br />...<br />&gt;&gt;&gt; rec = {"name": "John", "dept": "IT", "role": "Support"}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; store_record(**rec)<br />Storing name = John, role = Support, dept = IT, city = Pune<br />&gt;&gt;&gt;<br /><br /><br />## let’ say we have hundreds and function and all are returning some string<br />Once function is called we want to convert all return strings into upper case<br /><br />## one way is we can change return string under all functions. other is while calling we have to do call.upper() but this will be tedious since we need to do it across all the function<br /><br />Solution is:<br /><br />define one more function which can do it.<br />This is called a decorator. It takes once function and return another function<br /><br />def greet():<br />&nbsp; &nbsp; return "Hello world"<br /><br />def welcome():<br />&nbsp; &nbsp; return "Welcome to Python"<br /><br />def convert_to_upper(fn):<br />&nbsp; &nbsp; def wrapper():<br />&nbsp; &nbsp; &nbsp; &nbsp; return fn().upper()<br />&nbsp; &nbsp; return wrapper<br /><br /><br />print("greet =", greet) ## this will print a reference since we are not calling function<br />print(greet())&nbsp; ## calling original greet function<br />greet = convert_to_upper(greet)<br />print("greet =", greet) ## reference to convert_to_upper function<br />print(greet()) ## returns wrapper<br /><br /><br />runfile('/Users/nawlekha/Desktop/pyATS/decorator-working.py', wdir='/Users/nawlekha/Desktop/pyATS')<br />greet = <function 0x1811dfdea0="" at="" greet=""></function><br />Hello world<br />greet = <function convert_to_upper.="" locals="">.wrapper at 0x1811e5f0d0&gt;</function><br />HELLO WORLD<br /><br />## This is called as implementing cross-cutting function<br /><br />print("greet =", greet)<br />print(greet())<br />print(welcome)<br />print(welcome())<br />greet = convert_to_upper(greet)<br />welcome = convert_to_upper(welcome)<br />print("greet =", greet)<br />print(greet())<br />print(welcome())<br /><br />runfile('/Users/nawlekha/Desktop/pyATS/decorator-working.py', wdir='/Users/nawlekha/Desktop/pyATS')<br />greet = <function 0x10ad87158="" at="" greet=""></function><br />Hello world<br /><function 0x1811dfdea0="" at="" welcome=""></function><br />Welcome to Python<br />greet = <function convert_to_upper.="" locals="">.wrapper at 0x1811e5f378&gt;</function><br />HELLO WORLD<br />WELCOME TO PYTHON<br /><br /><br />## this syntax is simplified by python<br /><br />def convert_to_upper(fn):<br />&nbsp; &nbsp; def wrapper():<br />&nbsp; &nbsp; &nbsp; &nbsp; return fn().upper()<br />&nbsp; &nbsp; return wrapper<br /><br />@convert_to_upper<br />def greet():<br />&nbsp; &nbsp; return "Hello world"<br /><br />@convert_to_upper ## decorator function, @ is called annotation. annotation can be placed before fun or class<br />def welcome():<br />&nbsp; &nbsp; return "Welcome to Python"<br /><br />print("greet =", greet)<br />print("welcome =", welcome)<br /><br />print(greet())<br />print(welcome())<br /><br />runfile('/Users/nawlekha/Desktop/pyATS/decorator-working.py', wdir='/Users/nawlekha/Desktop/pyATS')<br />greet = <function convert_to_upper.="" locals="">.wrapper at 0x1811e5fae8&gt;&nbsp;</function><br />welcome = <function convert_to_upper.="" locals="">.wrapper at 0x1811e5f378&gt;</function><br />HELLO WORLD<br />WELCOME TO PYTHON<br /><br />Here is how it works.<br />decorator will take greet() function as an argument and whatever it will return is assigned to greet variable.<br /><br />## callable objects: functions, classes, and method underclasses are callable objects<br /><br />## understand the flow<br />def convert_to_upper(fn):<br />&nbsp; &nbsp; print("convert_to_upper called: fn =", fn)<br />&nbsp; &nbsp; def wrapper():<br />&nbsp; &nbsp; &nbsp; &nbsp; return fn().upper()<br />&nbsp; &nbsp; return wrapper<br /><br />@convert_to_upper ##while defining itself greet is called<br />def greet():<br />&nbsp; &nbsp; return "Hello world"<br /><br />print(greet())<br />print(greet())<br /><br />## Here decorator is called only once. The number of time annotation is used, decorator is called.<br /><br />runfile('/Users/nawlekha/Desktop/pyATS/decorator-working.py', wdir='/Users/nawlekha/Desktop/pyATS')<br />convert_to_upper called: fn = <function 0x181151e2f0="" at="" greet=""></function><br />HELLO WORLD<br />HELLO WORLD<br /><br /><br />def to_upper(fn):<br />&nbsp; &nbsp; def wrapper(n):<br />&nbsp; &nbsp; &nbsp; &nbsp; return fn(n).upper()<br />&nbsp; &nbsp; return wrapper<br /><br />@to_upper<br />def greet(name):<br />&nbsp; &nbsp; return "Hello " + name<br /><br />print(greet("John"))<br /><br />runfile('/Users/nawlekha/Desktop/pyATS/decorator-working.py', wdir='/Users/nawlekha/Desktop/pyATS')<br />HELLO JOHN<br /><br />Generalization<br />==============<br /><br />def to_upper(fn):<br />&nbsp; &nbsp; def wrapper(*args, **kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; return fn(*args, **kwargs).upper()<br />&nbsp; &nbsp; return wrapper<br /><br />@to_upper<br />def greet(name):<br />&nbsp; &nbsp; return "Hello " + name<br /><br /><br />@to_upper<br />def welcome(name,city):<br />&nbsp; &nbsp; return "Hello {}. Welcome to {}".format(name, city)<br /><br />print(greet("John"))<br /><br />print(welcome("Smith", "Bengaluru"))<br /><br /><br />HELLO JOHN<br />HELLO SMITH. WELCOME TO BENGALURU<br /><br /><br />Partials:<br />==========<br /><br />def store_record(name, role, dept, city):<br />&nbsp; &nbsp; print("Storing name = {}, role = {}, dept = {}, city = {}".format(name, role, dept, city))<br /><br /><br />store_record("John", "admin", "IT", "Bengaluru")<br />store_record("John", "admin", "IT", "Pune")<br />store_record("John", "admin", "IT", "Mumbai")<br />store_record("John", "admin", "IT", "Kolkatta")<br /><br />Storing name = John, role = admin, dept = IT, city = Bengaluru<br />Storing name = John, role = admin, dept = IT, city = Pune<br />Storing name = John, role = admin, dept = IT, city = Mumbai<br />Storing name = John, role = admin, dept = IT, city = Kolkatta<br /><br />## passing first three common arguments multiple times is cumbersome here<br /><br />Solution is hardcode first three arguments<br /><br />def partial_deco(fn):<br />&nbsp; &nbsp; def wrapper(city):<br />&nbsp; &nbsp; &nbsp; &nbsp; return fn("John", "admin", "IT", city)<br />&nbsp; &nbsp; return wrapper<br /><br />@partial_deco<br />def store_record(name, role, dept, city):<br />&nbsp; &nbsp; print("Storing name = {}, role = {}, dept = {}, city = {}".format(name, role, dept, city))<br /><br /><br />#store_record("John", "admin", "IT", "Bengaluru")<br />#store_record("John", "admin", "IT", "Pune")<br />#store_record("John", "admin", "IT", "Mumbai")<br />#store_record("John", "admin", "IT", "Kolkatta")<br /><br />store_record("Bengaluru")<br /><br />Storing name = John, role = admin, dept = IT, city = Bengaluru<br /><br />## other variation<br /><br />def partial_deco(fn):<br />&nbsp; &nbsp; def wrapper(**kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; defaults = {"name": "John", "role": "admin", "dept": "IT"}<br />&nbsp; &nbsp; &nbsp; &nbsp; if "city" not in kwargs:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise TypeError("city is required...")<br />&nbsp; &nbsp; &nbsp; &nbsp; defaults.update(kwargs)<br />&nbsp; &nbsp; &nbsp; &nbsp; return fn(**defaults)<br />&nbsp; &nbsp; return wrapper<br /><br />@partial_deco<br />def store_record(name, role, dept, city):<br />&nbsp; &nbsp; print("Storing name = {}, role = {}, dept = {}, city = {}".format(name, role, dept, city))<br /><br /><br />#store_record("John", "admin", "IT", "Bengaluru")<br />#store_record("John", "admin", "IT", "Pune")<br />#store_record("John", "admin", "IT", "Mumbai")<br />#store_record("John", "admin", "IT", "Kolkatta")<br /><br />store_record(city="Bengaluru")<br />store_record(name = "Smith", city="Bengaluru")<br />store_record(name = "Smith")<br /><br />Storing name = John, role = admin, dept = IT, city = Bengaluru<br />Storing name = Smith, role = admin, dept = IT, city = Bengaluru<br />TypeError: city is required...<br /><br />## if you want to initialize instance attribute the moment object is created, put them under __init__ method.<br /><br />NameError: looking for global variable which is not defined<br />AttributeError: trying to access attribute which is not defined in an object<br /><br />test(100)<br /><br />NameError: name 'test' is not defined<br /><br />os.getcwd()<br /><br />NameError: name 'os' is not defined<br /><br />sys.owner<br /><br />AttributeError: module 'sys' has no attribute 'owner'<br /><br />=========<br />&gt;&gt;&gt; def greet():<br />...&nbsp; &nbsp; &nbsp;a = 100<br />...&nbsp; &nbsp; &nbsp;val = 500<br />...&nbsp; &nbsp; &nbsp;name = "Smith"<br />...&nbsp; &nbsp; &nbsp;print(name, "says 'Hello'")<br />...<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; greet<br /><function 0x105b21e18="" at="" greet=""></function><br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a = greet<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a<br /><function 0x105b21e18="" at="" greet=""></function><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; del greet ## deleting greet will not delete greet function. There is still reference to greet function i.e. a<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; greet<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />NameError: name 'greet' is not defined<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a<br /><function 0x105b21e18="" at="" greet=""></function><br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; a()<br />Smith says 'Hello'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a<br /><function 0x105b21e18="" at="" greet=""></function><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; dir(a)<br />['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; a.__qualname__ ## name used during function definition<br />'greet'<br /><br />we can change it to some different name<br /><br />&gt;&gt;&gt; a.__qualname__ = "new_function"<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a<br /><function 0x105b21e18="" at="" new_function=""></function><br />&gt;&gt;&gt;<br /><br /><br />&gt;&gt;&gt; a.__code__<br /><code 0x105dea660="" at="" file="" greet="" object="" stdin="">", line 1&gt;</code><br /><br />## to find local variables defined in this function<br /><br />&gt;&gt;&gt; a.__code__.co_varnames<br />('a', 'val', 'name')<br />&gt;&gt;&gt;<br /><br />## to find byte code in binary format<br />&gt;&gt;&gt; a.__code__.co_code<br />b'd\x01}\x00d\x02}\x01d\x03}\x02t\x00|\x02d\x04\x83\x02\x01\x00d\x00S\x00'<br /><br />facade pattern<br />==============<br /><br />class Car:<br />&nbsp; &nbsp; def __init__(self, name,price):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.name, self.price = name, price<br />&nbsp; <br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Driving", self.name)<br /><br /><br />c = Car("honda", 10000)<br /><br />c<br />Out[13]: <__main__ .car="" 0x108bbf3c8="" at=""></__main__><br /><br />dir(c)<br />Out[14]:<br />['__class__',<br />&nbsp;'__delattr__',<br />&nbsp;'__dict__',<br />&nbsp;'__dir__',<br />&nbsp;'__doc__',<br />&nbsp;'__eq__',<br />&nbsp;'__format__',<br />&nbsp;'__ge__',<br />&nbsp;'__getattribute__',<br />&nbsp;'__gt__',<br />&nbsp;'__hash__',<br />&nbsp;'__init__',<br />&nbsp;'__init_subclass__',<br />&nbsp;'__le__',<br />&nbsp;'__lt__',<br />&nbsp;'__module__',<br />&nbsp;'__ne__',<br />&nbsp;'__new__',<br />&nbsp;'__reduce__',<br />&nbsp;'__reduce_ex__',<br />&nbsp;'__repr__',<br />&nbsp;'__setattr__',<br />&nbsp;'__sizeof__',<br />&nbsp;'__str__',<br />&nbsp;'__subclasshook__',<br />&nbsp;'__weakref__',<br />&nbsp;'drive',<br />&nbsp;'name',<br />&nbsp;'price']<br /><br />c.name<br />Out[15]: 'honda'<br /><br />c.price<br />Out[16]: 10000<br /><br />c.drive()<br />Driving honda<br /><br />c.color<br />Traceback (most recent call last):<br /><br />&nbsp; File "<ipython-input-18-411cec27a36a>", line 1, in <module></module></ipython-input-18-411cec27a36a><br />&nbsp; &nbsp; c.color<br /><br />AttributeError: 'Car' object has no attribute 'color'<br /><br />## we can handle this attribute error<br /><br />class Car:<br />&nbsp; &nbsp; def __init__(self, name,price):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.name, self.price = name, price<br />&nbsp; <br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Driving", self.name)<br />&nbsp; <br />&nbsp; &nbsp; def __getattr__(self, attr):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Get-attr called!")<br />&nbsp; &nbsp; &nbsp; &nbsp; return 100<br /><br /><br />Now if any attributes is not found and if we have defined __getattr__ function it will call this function<br /><br />c = Car("Honda", 1000000000)<br /><br />c.name<br />Out[31]: 'Honda'<br /><br />c.price<br />Out[32]: 1000000000<br /><br />c.color<br />Get-attr called!<br />Out[33]: 100<br /><br />c.owner<br />Get-attr called!<br />Out[34]: 100<br /><br />## all attributes are stored as dictionary in instance<br /><br />Instead of that we want to store it somewhere else, in outside dict<br /><br />attrs = {}<br /><br />class Car:<br />&nbsp; &nbsp; def __init__(self, name, price):<br />&nbsp; &nbsp; &nbsp; &nbsp; attrs[id(self)] = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; attrs[id(self)]['name'] = name<br />&nbsp; &nbsp; &nbsp; &nbsp; attrs[id(self)]['price'] = price<br />&nbsp; <br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Driving", self.name)<br />&nbsp; <br />&nbsp; &nbsp; def __getattr__(self, attr):<br />&nbsp; &nbsp; &nbsp; &nbsp; return attrs[id(self)][attr]<br /><br />&nbsp; &nbsp; def __setattr__(self, attr, value):<br />&nbsp; &nbsp; &nbsp; &nbsp; attrs[id(self)][attr]] = value<br /><br /><br />attrs<br />Out[36]: {}<br /><br />c = Car("Honda", 100000)<br /><br />attrs<br />Out[38]: {4441491888: {'name': 'Honda', 'price': 100000}}<br /><br />c2 = Car("Maruti", 50000)<br /><br />attrs<br />Out[42]:<br />{4441491888: {'name': 'Honda', 'price': 100000},<br />&nbsp;4441567752: {'name': 'Maruti', 'price': 50000}}<br /><br />c.name ## getting value but attribute is not there in dir(c). It's getting from outside dict<br />Out[45]: 'Honda'<br /><br />dir(c)<br />Out[46]:<br />['__class__',<br />&nbsp;'__delattr__',<br />&nbsp;'__dict__',<br />&nbsp;'__dir__',<br />&nbsp;'__doc__',<br />&nbsp;'__eq__',<br />&nbsp;'__format__',<br />&nbsp;'__ge__',<br />&nbsp;'__getattr__',<br />&nbsp;'__getattribute__',<br />&nbsp;'__gt__',<br />&nbsp;'__hash__',<br />&nbsp;'__init__',<br />&nbsp;'__init_subclass__',<br />&nbsp;'__le__',<br />&nbsp;'__lt__',<br />&nbsp;'__module__',<br />&nbsp;'__ne__',<br />&nbsp;'__new__',<br />&nbsp;'__reduce__',<br />&nbsp;'__reduce_ex__',<br />&nbsp;'__repr__',<br />&nbsp;'__setattr__',<br />&nbsp;'__sizeof__',<br />&nbsp;'__str__',<br />&nbsp;'__subclasshook__',<br />&nbsp;'__weakref__',<br />&nbsp;'drive']<br /><br />=========<br />## private methods. Not accessible from outside world<br /><br />class Car:<br />&nbsp; &nbsp; def __sell(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car sold...")<br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.__sell()<br /><br />c = Car()<br /><br />c.drive()<br />Car sold...<br /><br />c.__sell()<br />Traceback (most recent call last):<br /><br />&nbsp; File "<ipython-input-56-34f763c0382b>", line 1, in <module></module></ipython-input-56-34f763c0382b><br />&nbsp; &nbsp; c.__sell()<br /><br />AttributeError: 'Car' object has no attribute '__sell'<br /><br />Note : if you define anything with __word then it is not accessible to outside world.<br /><br />There is a different way to access it.<br /><br />c._Car__sell<br />Out[59]: <bound 0x108bcff98="" at="" car.__sell="" main__.car="" method="" object="" of="">&gt;</bound><br /><br />c._Car__sell()<br />Car sold...<br /><br />Unicode vs byte array in Python<br />========================<br />Suppose you create a string using Python 3 in the usual way:<br />stringobject = 'ant'<br />stringobject would be a unicode string.<br />A unicode string is made up of unicode characters. In string object above, the unicode characters are the individual letters, e.g. a, n, t<br />Each unicode character is assigned a code point, which can be expressed as a sequence of hex digits (a hex digit can take on 16 values, ranging from 0-9 and A-F). For instance, the letter 'a' is equivalent to '\u0091', and 'ant' is equivalent to '\u0061\u006E\u0074'.<br />So you will find that if you type in,<br />stringobject = '\u0061\u006E\u0074'<br />stringobject<br />You will also get the output 'ant'.<br />Now, unicode is converted to bytes, in a process known as encoding. The reverse process of converting bytes to unicode is known as decoding.<br />How is this done? Since each hex digit can take on 16 different values, it can be reflected in a 4-bit binary sequence (e.g. the hex digit 0 can be expressed in binary as 0000, the hex digit 1 can be expressed as 0001 and so forth). If a unicode character has a code point consisting of four hex digits, it would need a 16-bit binary sequence to encode it.<br />Different encoding systems specify different rules for converting unicode to bits. Most importantly, encodings differ in the number of bits they use to express each unicode character.<br />For instance, the ASCII encoding system uses only 8 bits (1 byte) per character. Thus it can only encode unicode characters with code points up to two hex digits long (i.e. 256 different unicode characters). The UTF-8 encoding system uses 8 to 32 bits (1 to 4 bytes) per character, so it can encode unicode characters with code points up to 8 hex digits long, i.e. everything.<br />Running the following code:<br />byteobject = stringobject.encode('utf-8')<br />byteobject, type(byteobject)<br />converts a unicode string into a byte string using the utf-8 encoding system, and returns b'ant', bytes'.<br />Note that if you used 'ASCII' as the encoding system, you wouldn't run into any problems since all code points in 'ant' can be expressed with 1 byte. But if you had a unicode string containing characters with code points longer than two hex digits, you would get a UnicodeEncodeError.<br />Similarly,<br />stringobject = byteobject.decode('utf-8')<br />stringobject, type(stringobject)<br />gives you 'ant', str.<br /><br />The only thing that a computer can store is bytes.<br />To store anything in a computer, you must first encode it, i.e. convert it to bytes. For example:<br /><span style="white-space: pre;"> </span>•<span style="white-space: pre;"> </span>If you want to store music, you must first encode it using MP3, WAV, etc.<br /><span style="white-space: pre;"> </span>•<span style="white-space: pre;"> </span>If you want to store a picture, you must first encode it using PNG, JPEG, etc.<br /><span style="white-space: pre;"> </span>•<span style="white-space: pre;"> </span>If you want to store text, you must first encode it using ASCII, UTF-8, etc.<br />MP3, WAV, PNG, JPEG, ASCII and UTF-8 are examples of encodings. An encoding is a format to represent audio, images, text, etc in bytes.<br />In Python, a byte string is just that: a sequence of bytes. It isn't human-readable. Under the hood, everything must be converted to a byte string before it can be stored in a computer.<br />On the other hand, a character string, often just called a "string", is a sequence of characters. It is human-readable. A character string can't be directly stored in a computer, it has to be encoded first (converted into a byte string). There are multiple encodings through which a character string can be converted into a byte string, such as ASCII and UTF-8.<br />'I am a string'.encode('ASCII')<br />The above Python code will encode the string 'I am a string' using the encoding ASCII. The result of the above code will be a byte string. If you print it, Python will represent it as b'I am a string'. Remember, however, that byte strings aren't human-readable, it's just that Python decodes them from ASCII when you print them. In Python, a byte string is represented by a b, followed by the byte string's ASCII representation.<br />A byte string can be decoded back into a character string if you know the encoding that was used to encode it.<br />b'I am a string'.decode('ASCII')<br />The above code will return the original string 'I am a string'.<br />Encoding and decoding are inverse operations. Everything must be encoded before it can be written to disk, and it must be decoded before it can be read by a human.<br /><br />If you are running file directly then file name is __main__<br />if you are running file by importing first file then it will print first file name<br /><br />Generator doesn’t hold entire result in memory.<br />Generator is better with performance<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com0tag:blogger.com,1999:blog-6880492769470667099.post-33009341818855338732017-10-22T12:48:00.001+05:302018-09-10T16:40:40.605+05:30Python Beyond Basics<div dir="ltr" style="text-align: left;" trbidi="on"><b>arithmetic operations</b><br />c = a + b&nbsp; &nbsp;# c = a.__add__(b)<br />c = a - b&nbsp; &nbsp;# c = a.__sub__(b)<br />c = a * b&nbsp; &nbsp;# c = a.__mul__(b)<br />c = a / b&nbsp; &nbsp;# c = a.__div__(b)<br />c = a % b&nbsp; &nbsp;# c = a.__mod__(b)<br />c = a // b&nbsp; # c = a.__floordiv__(b)<br />c = a ** b&nbsp; # c = a.__pow__(b)<br /><br />c = -a&nbsp; &nbsp; &nbsp; # c = a.__neg__()<br /><br />c = a | b&nbsp; &nbsp;# c = a.__or__(b)<br />c = a &amp; b&nbsp; &nbsp;# c = a.__and__(b)<br />c = a ^ b&nbsp; &nbsp;# c = a.__xor__(b)<br />c = ~a&nbsp; &nbsp; &nbsp; <br /><br />c = a &lt;&lt; 1&nbsp; # c = a.__lshift__(1)<br />c = a &gt;&gt; 1&nbsp; # c = a.__rshift__(1)<br />===<br /><br /><b>assignments</b><br />Simple statements<br />---------------------<br />1. Simple assignment<br />&nbsp; &nbsp;a = 10<br />&nbsp; &nbsp;b = 20<br /><br />2. Tuple packing<br />&nbsp; &nbsp;a = 10, 20, 30<br /><br />3. Tuple unpacking<br />&nbsp; &nbsp;b, c, d = a<br /><br />4. Parallel assignment<br />&nbsp; &nbsp;a, b = 10, 20<br /><br />5. Assignment chainloading<br />&nbsp; &nbsp;a = b = c = 10<br />&nbsp; <br />6. Augmented assignments<br />&nbsp; &nbsp;a += 10<br />----------------------------<br />del variable_name<br /><br />print variable, expression<br />====<br /><b><br /></b><b>boolean expression</b><br />&nbsp;==<br />&nbsp;!= &lt;&gt;<br />&nbsp;&lt;<br />&nbsp;&gt;<br />&nbsp;&lt;=<br />&nbsp;&gt;=<br /><br />&nbsp;is<br />&nbsp;is not<br /><br />&nbsp;and<br />&nbsp;or<br />&nbsp;not<br /><br />&nbsp;a == b<br />a &lt; b<br />a &gt; b<br />a &lt;= b<br />a &gt;= b<br /><br />a != b<br />a &lt;&gt; b&nbsp; &nbsp;# only in python2<br /><br />a is b<br />a is not b<br /><br />element in collection<br />"with" in "this is a test string with some words"<br />10 in (33, 44, 10, 44, 33, 44)<br /><br />not in<br /><br />not<br />and<br />or<br /><br />conditional expression<br /><br />a == b<br />a != b, a &lt;&gt; b<br />a &gt; b<br />a &lt; b<br />a &gt;= b<br />a &lt;= b<br /><br />a is b<br />a is not b<br /><br />33 in (11, 22, 33, 44, 55, 66)<br /><br />"test" not in "this is a dummy string"<br /><br />and<br />or<br />not<br /><br />if not a == b<br />if a != b<br />&nbsp;======<br /><br /><b>&nbsp;boolean context</b><br /><br />&nbsp; 0, 0.0, "", (), [], {}, False, None -&gt; False<br />=====<br /><br /><b>1. Boolean comparison operators</b><br />-------------------------------<br />&nbsp; &nbsp; ==<br />&nbsp; &nbsp; != &lt;&gt;<br />&nbsp; &nbsp; &lt;<br />&nbsp; &nbsp; &gt;<br />&nbsp; &nbsp; &lt;=<br />&nbsp; &nbsp; &gt;=<br /><br />&nbsp; &nbsp; is<br />&nbsp; &nbsp; is not<br /><br />&nbsp; &nbsp; in<br />&nbsp; &nbsp; not in<br /><br />&nbsp; &nbsp; Examples<br />&nbsp; &nbsp; --------<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a = 10<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; b = 10<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a == b<br />&nbsp; &nbsp; &nbsp; &nbsp; True<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt;<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; c = 20<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a &gt; c<br />&nbsp; &nbsp; &nbsp; &nbsp; False<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a &lt; c<br />&nbsp; &nbsp; &nbsp; &nbsp; True<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a != c<br />&nbsp; &nbsp; &nbsp; &nbsp; True<br /><br /><b>2. Logical evaluation operators</b><br />-------------------------------<br />&nbsp; &nbsp; and<br />&nbsp; &nbsp; or<br />&nbsp; &nbsp; not<br /><br />&nbsp; &nbsp; Examples<br />&nbsp; &nbsp; --------<br />&nbsp; &nbsp; &gt;&gt;&gt; a = 10<br />&nbsp; &nbsp; &gt;&gt;&gt; b = 20<br />&nbsp; &nbsp; &gt;&gt;&gt; c = 30<br />&nbsp; &nbsp; &gt;&gt;&gt; b &gt; a and b &lt; c<br />&nbsp; &nbsp; True<br />&nbsp; &nbsp; &gt;&gt;&gt; a == 10 or b == 100<br />&nbsp; &nbsp; True<br /><br /><b>3. Special boolean operators</b><br />----------------------------<br />&nbsp; &nbsp; is<br />&nbsp; &nbsp; is not<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; Example<br />&nbsp; &nbsp; &nbsp; &nbsp; -------<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a = "Hello world"<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; b = "Hello world"<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; c = a<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a is b<br />&nbsp; &nbsp; &nbsp; &nbsp; False<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a is c<br />&nbsp; &nbsp; &nbsp; &nbsp; True<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a is not b<br />&nbsp; &nbsp; &nbsp; &nbsp; True<br /><br />&nbsp; &nbsp; in<br />&nbsp; &nbsp; not in<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; Example<br />&nbsp; &nbsp; &nbsp; &nbsp; -------<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; a = 33, 44, 55, 32, 12, 56, 77<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 44 in a<br />&nbsp; &nbsp; &nbsp; &nbsp; True<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 100 not in a<br />&nbsp; &nbsp; &nbsp; &nbsp; True<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; 67 in a<br />&nbsp; &nbsp; &nbsp; &nbsp; False<br /><b><br /></b><b>4. Boolean context</b><br />------------------<br />false_values = False, None, 0, 0.0, "", (), [], {}<br />====<br /><br /><b>built-in function types</b><br />1. Type constructors (type conversion functions)<br />2. Generalized functions (work on broader range of object types)<br />3. Introspection functions<br />====<br /><br />&nbsp;If you have a quote in the middle of the string? Python needs help to recognize quotes as part of the English language and not as part of the Python language.<br />&gt;&gt;&gt; “I can’t do that”<br />“I can’t do that”<br />&nbsp;&gt;&gt;&gt; “He said \“no\” to me”<br />“He said “no” to me”<br /><br /><br /><b>Conditional statements:</b><br />=======================<br />&nbsp; &nbsp; ##############################################################<br />&nbsp; &nbsp; if [boolean-expression]:<br />&nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; elif [another-boolean-expression]:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /><true-statement4></true-statement4><br />&nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; <false-statement1></false-statement1><br />&nbsp; &nbsp; &nbsp; &nbsp; <false-statement2></false-statement2><br />&gt;&gt;&gt; num = 21<br />&gt;&gt;&gt; if num == 20:<br />... print 'the number is 20'<br />... elif num &gt; 20:<br />... print 'the number is greater then 20'<br />... else:<br />... print 'the number is less then 20'<br />...<br />the number is greater then 20<br /><br /><br />&nbsp; &nbsp; ###############################################################<br />&nbsp; &nbsp; if [boolean-expression]: <true-statement></true-statement><br /><br /><div class="p1"><span class="s1">&gt;&gt;&gt; if num == 10:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>print("The number is 10")</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p1"><span class="s1">The number is 10</span></div><br />&nbsp; &nbsp; ###############################################################<br />&nbsp; &nbsp; <true-statement> if [boolean-expression] else <false-statement></false-statement></true-statement><br /><br />&gt;&gt;&gt; num = 20<br />&gt;&gt;&gt; if num == 20:<br />... print 'the number is 20'<br />... else:<br />... print 'the number is not 20'<br />...<br />the number is 20<br /><br /><br /><b>Loops:</b><br />======<br />&nbsp; &nbsp; ###############################################################<br />&nbsp; &nbsp; while [boolean-expression]:<br />&nbsp; &nbsp; &nbsp; &nbsp; <statement1></statement1><br />&nbsp; &nbsp; &nbsp; &nbsp; <statement2></statement2><br />&nbsp; &nbsp; &nbsp; &nbsp; if [some-condition]: break<br />&nbsp; &nbsp; &nbsp; &nbsp; if [some-other-condition]: continue<br />&nbsp; &nbsp; &nbsp; &nbsp; <statement3></statement3><br />&nbsp; &nbsp; &nbsp; &nbsp; ....<br />&nbsp; &nbsp; &nbsp; &nbsp; <statement-n></statement-n><br />&nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; <statements-to-be-executed-if-loop-condition-fails></statements-to-be-executed-if-loop-condition-fails><br /><div class="p1"><span class="s1">&gt;&gt;&gt; num = 1</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; while num &lt;= 5:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>print(num)</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>num += 1</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">1</span></div><div class="p1"><span class="s1">2</span></div><div class="p1"><span class="s1">3</span></div><div class="p1"><span class="s1">4</span></div><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p1"><span class="s1">5</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; i = 1</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; while i &lt; 6:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>print(i)</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>if i == 3:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>break</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>i += 1</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">1</span></div><div class="p1"><span class="s1">2</span></div><div class="p1"><span class="s1"> <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">3</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; i = 0</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; while i &lt; 6:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>i += 1</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>if i == 3:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>continue</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>print(i)</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">1</span></div><div class="p1"><span class="s1">2</span></div><div class="p1"><span class="s1">4</span></div><div class="p1"><span class="s1">5</span></div><div class="p1"><span class="s1"> <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">6</span></div><div class="p1"><br /></div>&nbsp; &nbsp; ###############################################################<br />&nbsp; &nbsp; for element in iterable:<br />&nbsp; &nbsp; &nbsp; &nbsp; <statement1></statement1><br />&nbsp; &nbsp; &nbsp; &nbsp; <statement2></statement2><br />&nbsp; &nbsp; &nbsp; &nbsp; if [some-condition]: break<br />&nbsp; &nbsp; &nbsp; &nbsp; if [some-other-condition]: continue<br />&nbsp; &nbsp; &nbsp; &nbsp; <statement3></statement3><br />&nbsp; &nbsp; &nbsp; &nbsp; ...<br />&nbsp; &nbsp; &nbsp; &nbsp; <statement-n></statement-n><br />&nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; <statements-to-be-executed-no-more-elements-from-iterable></statements-to-be-executed-no-more-elements-from-iterable><br /><br /><div class="p1"><span class="s1">&gt;&gt;&gt; colors = ('red','blue','green')</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; colors</span></div><div class="p1"><span class="s1">('red', 'blue', 'green')</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; for favorite in colors:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>print("I love", favorite)</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">I love red</span></div><div class="p1"><span class="s1">I love blue</span></div><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p1"><span class="s1">I love green</span></div><br /><div class="p1"><span class="s1">&gt;&gt;&gt; fruits = ["apple", "banana", "cherry"]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; for x in fruits:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>if x == "banana":</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>break</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>print(x)</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p1"><span class="s1">apple</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; fruits = ["apple", "banana", "cherry"]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; for x in fruits:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>if x == "banana":</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>continue</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>print(x)</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">apple</span></div><div class="p1"><span class="s1"> <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">cherry</span></div><br /><b>Exception handling:</b><br />===================<br />&nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; <statement1></statement1><br />&nbsp; &nbsp; &nbsp; &nbsp; <statement2></statement2><br />&nbsp; &nbsp; except SomeError as error_object:<br />&nbsp; &nbsp; &nbsp; &nbsp; <error-handling-statements></error-handling-statements><br />&nbsp; &nbsp; except SomeOtherError as error_object:<br />&nbsp; &nbsp; &nbsp; &nbsp; <error-handling-statements></error-handling-statements><br />&nbsp; &nbsp; except Exception as error_object:<br />&nbsp; &nbsp; &nbsp; &nbsp; <catch-all-error-handling-statements></catch-all-error-handling-statements><br />&nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; <statements-to-be-executed-if-no-exceptions></statements-to-be-executed-if-no-exceptions><br />&nbsp; &nbsp; finally:<br />&nbsp; &nbsp; &nbsp; &nbsp; <statements-to-be-executed-if-exceptions-or-no-exceptions></statements-to-be-executed-if-exceptions-or-no-exceptions><br /><br /><b>Context management:</b><br />===================<br />&nbsp; &nbsp; with <context-manager-expression> as object:</context-manager-expression><br />&nbsp; &nbsp; &nbsp; &nbsp; <statement1></statement1><br />&nbsp; &nbsp; &nbsp; <br />Function definition:<br />====================<br />&nbsp; &nbsp; def function_name():<br />&nbsp; &nbsp; &nbsp; &nbsp;<function-body-statements></function-body-statements><br /><div class="p1"><span class="s1">&gt;&gt;&gt; def my_function():</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; </span>print("Hello from a function")</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; my_function()</span></div><div class="p1"><span class="s1">Hello from a function</span></div><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><br />Class definition:<br />=================<br />&nbsp; &nbsp; class ClassName:<br />&nbsp; &nbsp; &nbsp; &nbsp;<class-body-definitions></class-body-definitions><br />&nbsp; &nbsp; &nbsp; &nbsp;....<br /><br />Create a class named Person, use the __init__() function to assign values for name and age:<br /><br />class Person:<br />&nbsp; def __init__(self, name, age):<br />&nbsp; &nbsp; self.name = name<br />&nbsp; &nbsp; self.age = age<br /><br />p1 = Person("John", 36)<br /><br />print(p1.name)<br />print(p1.age)<br /><br /><br />=====<br /><br /><b>Data types</b><br /><br />NoneType -&gt; None<br /><br />bool -&gt; True, False<br /><br />Numeric<br />&nbsp; &nbsp;int, float, long, complex<br />&nbsp; &nbsp;fractions.Decimal, fractions.Fraction<br /><br /><b>Iterable Objects</b><br />&nbsp; &nbsp;Collection<br />&nbsp; &nbsp; &nbsp; Sequences&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; Ordered collection of elements<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str (String)&nbsp; &nbsp; &nbsp; -&gt; "hello", 'hello', """hello""", r'hello'<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;unicode&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; u'hello world'<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tuple&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; (10, "hello", 3.4)<br />-----------------------------------------------------------------------------------<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bytearray&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; bytearray('hello world')<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;list&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; [10, "hello", 3.4]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;collections.deque -&gt; deque([22, 33, 44, 55])<br /><br />&nbsp; &nbsp; &nbsp; Set&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; Unordered collection of unique hashable objects<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-&gt; {33, 44, 54, 12, 56}<br /><br />&nbsp; &nbsp; &nbsp; MappingType&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; Unordered collection of key:value pair<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dict&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"name" : "Smith",<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"city" : "New York",<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"host" : "44.33.21.45",<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"port" : 8080<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;collections.OrderedDict<br /><br />&nbsp; &nbsp;xrange object<br />&nbsp; &nbsp;File objects<br />&nbsp; &nbsp;Generators<br />&nbsp; &nbsp;Views<br />====<br /><br /><b>definitions</b><br />1. Assignment statement<br />-----------------------<br />a = 100<br />name = "john"<br /><br />2. function definition<br />----------------------<br />def greet(): print "Hello world"<br /><br />3. module definition / module loading<br />-------------------------------------<br />import sys<br />from sys import version<br /><br />4. class definition<br />-------------------<br />class Person: pass<br /><br />To remove variable:<br />&nbsp; &nbsp;del variablename<br />=====<br /><b><br /></b><b>equality</b><br />==&nbsp; &nbsp; &nbsp; a == 10, b == "john"<br />!=<br />&lt;<br />&gt;<br />&lt;=<br />&gt;=<br /><br />in&nbsp; &nbsp; &nbsp; "john" in names,<br />not in&nbsp; 10 not in numbers<br /><br />is&nbsp; &nbsp; &nbsp; -&gt; check whether two variables refer to same object<br />is not<br />========<br /><br /><b>exception</b><br /><br />Parse Errors (errors while parsing the python program):<br />&nbsp; &nbsp;- SyntaxError<br />&nbsp; &nbsp;- IndentationError<br /><br />Runtime Errors<br />--------------<br />&nbsp; &nbsp; NameError -&gt; invalid variable name or access to undefined variable<br />&nbsp; &nbsp; TypeError -&gt; invalid type detected or object type is incompatible<br />&nbsp; &nbsp; ValueError -&gt; incompatible value detected.<br />&nbsp; &nbsp; IndexError -&gt; invalid index in a sequence<br />&nbsp; &nbsp; KeyError&nbsp; &nbsp;-&gt; invalid key in a map<br />&nbsp; &nbsp; AttributeError -&gt; invalid attribute on an object<br /><br />&nbsp; &nbsp; IOError -&gt; invalid file or socket I/O operation<br />&nbsp; &nbsp; OSError -&gt; error while executing underlying OS syscall<br />======<br /><br /><b>for loop</b><br />a = "Hello"<br />for c in a: print c,<br /><br />H<br />e<br />l<br />l<br />o<br /><br />it = iter(a)<br /><br />try:<br />&nbsp; &nbsp;while True:<br />&nbsp; &nbsp; &nbsp; c = it.next()<br />&nbsp; &nbsp; &nbsp; print c,<br />except StopIteration:<br />&nbsp; &nbsp;pass<br />&nbsp; <br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 3, in <module></module></stdin><br />AttributeError: 'str_iterator' object has no attribute 'next'&nbsp; <br />=====<br /><br /><b>Identifiers</b><br />In Python, identifiers can be:<br />&nbsp; a. variable name<br />&nbsp; b. function name<br />&nbsp; c. class name<br />&nbsp; d. module name<br />&nbsp; e. constants<br /><br />Naming conventions<br />------------------<br />1. Variables<br />&nbsp; &nbsp;count<br />&nbsp; &nbsp;name<br />&nbsp; <br />&nbsp; &nbsp;word_count<br />&nbsp; &nbsp;program_name<br /><br />2. Functions<br />&nbsp; &nbsp;is_prime()<br />&nbsp; &nbsp;generate_primes()<br /><br />&nbsp; &nbsp;gen_values()<br /><br />3. Classes<br />&nbsp; &nbsp;EmployeeInfo<br /><br />4. Modules<br />&nbsp; &nbsp;sys<br />&nbsp; &nbsp;os<br />&nbsp; &nbsp;flask<br /><br />5. Constants<br />&nbsp; &nbsp;---------<br />&nbsp; &nbsp;MAX = 100<br />&nbsp; &nbsp;MAX_VALUE = 500<br />====<br /><br /><b>Immutable types</b><br />NoneType (None)<br />bool (True / False)<br />numbers (int, float, long, complex)<br />sequences -&gt; str, unicode, tuple<br />set -&gt; frozenset<br />=====<br /><br /><b>Introspection function</b><br />type(variable)<br />id(variable)<br />dir(variable)<br />help(variable)<br />help(variable.attribute)<br />====<br /><br /><b>naming conventions</b><br />All variable names should start with lower-case and contain alphabets and _<br />&nbsp; &nbsp; max_count<br />&nbsp; &nbsp; user_name<br /><br />functions must start with a verb<br />&nbsp; &nbsp; run_command<br />&nbsp; &nbsp; start_process<br />&nbsp; &nbsp; kill_process<br />&nbsp; &nbsp; wait_for_thread<br /><br />Module names must also start with lower-case and contain alphabets and _<br />&nbsp; &nbsp; import time<br />&nbsp; &nbsp; import sys<br /><br />boolean functions start with is_<br />&nbsp; &nbsp; is_prime()<br />&nbsp; &nbsp; is_lower()<br /><br />All classes follow CamelCase convention and start with Capital letter<br />&nbsp; &nbsp; CustomerOrder<br />&nbsp; &nbsp; InvoiceInfo<br /><br />Constants are all capital letters<br />&nbsp; &nbsp; MAX_COUNT<br />&nbsp; &nbsp; PI_VALUE<br />====<br /><br />1. All variables are references to Objects<br />2. All identifiers are variables<br />&nbsp; &nbsp;a. Function name<br />&nbsp; &nbsp;b. Class name<br />&nbsp; &nbsp;c. Module name<br />&nbsp; &nbsp;d. Other variable names<br /><br />3. All assignments are "assign by references"<br />4. Every object is uniquely identified by the object-id.<br />=====<br /><b><br /></b><b>numeric operater</b><br />+<br />-<br />*<br />/<br />%<br /><br />**&nbsp; &nbsp;power<br />//&nbsp; &nbsp;floordiv<br />====<br /><br /><b>Object types</b><br />Immutable objects<br />Hashable objects<br />Iterable objects<br />&nbsp; &nbsp; &nbsp;Collection<br />&nbsp; &nbsp; &nbsp; &nbsp; -&gt; Sequence : An ordered collection of items<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str (string)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;unicode<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bytearray<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tuple&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />=====<br /><b><br /></b><b>references</b><br />Variables<br />Attributes of an object<br />Index of a sequence<br />Key of a mapping<br />:<br />====<br /><br /><b>sequence operator</b><br />+&nbsp; &nbsp; Concatenation<br />*&nbsp; &nbsp; Repetition<br />%&nbsp; &nbsp; String format operator<br />====<br /><br /><b>sequence function</b><br />sum()<br />max(), min(), all(), any()<br /><br />sorted(), reversed()<br /><br />enumerate(), zip(), itertools.izip()<br /><br />iter()<br /><br />len()<br />====<br /><br /><b>sequences</b><br />Sequences -&gt; str, unicode, tuple, list, bytearray, buffer<br />Sequence operations<br />-------------------<br />&nbsp; +&nbsp; concatenation<br />&nbsp; &nbsp; &nbsp;a = 10, 20, 30<br />&nbsp; &nbsp; &nbsp;b = 40, 50, 60<br />&nbsp; &nbsp; &nbsp;c = a + b<br />&nbsp; &nbsp; &nbsp;print c<br />&nbsp; &nbsp; &nbsp;10, 20, 30, 40, 50, 60<br /><br />&nbsp; * repetition<br />&nbsp; &nbsp; &nbsp;a = 10, 20<br />&nbsp; &nbsp; &nbsp;b = a * 5<br />&nbsp; &nbsp; &nbsp;print b<br />&nbsp; &nbsp; &nbsp;10, 20, 10, 20, 10, 20, 10, 20 ...<br /><br />&nbsp; [] indexing<br />&nbsp; &nbsp; &nbsp;a[0]<br />&nbsp; &nbsp; &nbsp;a[-1]<br />&nbsp; &nbsp; &nbsp;a[2:3]<br />&nbsp; &nbsp; &nbsp;a[::2]<br /><br />Sequence methods<br />----------------<br />&nbsp; &nbsp;a.index(element)<br />&nbsp; &nbsp;a.count(element)<br /><br />General sequence functions<br />--------------------------<br />len(s)<br />min(s)<br />max(s)<br />all(s)<br />any(s)<br /><br />sum(s)<br /><br />zip(s1, s2)<br />enumerate(s)<br /><br />reversed(s)<br />sorted(s)<br />=====<br /><br /><b>statements</b><br />1. print tuple&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Prints each element of a tuple as a string<br />&nbsp; &nbsp;print "Hello world", "another string", 10, 5.6<br /><br />2. Assignments<br />&nbsp; &nbsp;a = 10&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# simple assignment<br />&nbsp; &nbsp;a = 10, 20&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# tuple packing<br />&nbsp; &nbsp;b, c = a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# tuple unpacking<br />&nbsp; &nbsp;a, b = 10, 20&nbsp; &nbsp; &nbsp; &nbsp; # parallel assignment<br />&nbsp; &nbsp;a += 5&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# augmented assignment<br />&nbsp; &nbsp;a = b = c = 10&nbsp; &nbsp; &nbsp; &nbsp;# assignment chain-loading<br /><br />3. del variable_or_ref&nbsp; # Remove a variable or a reference&nbsp; <br />&nbsp; &nbsp;del a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Remove the variable 'a' and<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # decrement the reference count<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # of the object referred by 'a'<br /><br />4. import module&nbsp; &nbsp; &nbsp; &nbsp; # Load a module and in the module namespace<br /><br />&nbsp; &nbsp;import sys&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Load a module called 'sys'<br />&nbsp; &nbsp;sys.version&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Access members of 'sys' module using 'sys' namespace<br /><br />&nbsp; &nbsp;import sys as system # Load a module called 'sys' under 'system' namespace<br />&nbsp; &nbsp;system.version&nbsp; &nbsp; &nbsp; &nbsp;# Access member called 'version' from<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # 'system' namespace<br /><br />5. from module import member&nbsp; # Load a module and make members of that module<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # accessible in the current namespace<br /><br />&nbsp; &nbsp;from sys import getsizeof&nbsp; # getsizeof() function can now be accessed<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # directly without namespace resolution.<br /><br /><br />&nbsp; &nbsp;from sys import getsizeof as sizeof&nbsp; &nbsp; # import a member named 'getsizeof'<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # from module named 'sys' as a<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new name 'sizeof'<br /><br />6. pass&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Represent a do-nothing statement<br /><br />7. raise SomeError&nbsp; &nbsp; &nbsp; # Raise a runtime exception of type SomeError<br /><br />8. assert expression&nbsp; &nbsp; # Assert expression to be true<br />-------------------------------------------------------------------------------<br />Other simple statements<br />-----------------------<br />9.&nbsp; return value&nbsp; &nbsp; &nbsp; &nbsp; # Return a value from a function<br />10. break&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Break out of a while/for loop<br />11. continue&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Skip to next iteration of while/for loop<br />12. yield value&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Yield a value to the generator<br />13. global variable&nbsp; &nbsp; &nbsp;# Declare a variable in a function to be global<br />===<br /><br /><b>special methods</b><br />+&nbsp; &nbsp;__add__<br />-&nbsp; &nbsp;__sub__<br />*&nbsp; &nbsp;__mul__<br />/&nbsp; &nbsp;__div__<br />**&nbsp; __pow__<br />//&nbsp; __floordiv__<br />%&nbsp; &nbsp;__mod__<br /><br />&lt;&lt;&nbsp; __lshift__<br />&gt;&gt;&nbsp; __rshift__<br />|&nbsp; &nbsp;__or__<br />&amp;&nbsp; &nbsp;__and__<br />^&nbsp; &nbsp;__xor__<br />~&nbsp; &nbsp;__neg__<br />+= __iadd__&nbsp; &nbsp; # a += 1 --&gt; a.__iadd__(1)<br />-= __isub__<br />....<br />a == b<br />a.__cmp__(b) == 0<br /><br />a &gt; b<br />a.__cmp__(b) &gt; 0<br /><br />a &lt; b<br />a.__cmp__(b) &lt; 0<br />====<br /><br /><b>strings</b><br />a = "He said - I'll be back"<br />a = 'He said "I will be back" and we waited'<br />a = "He said - \"I'll be back\" and we waited"<br />a = 'He said - "I\'ll be back" and we waited'<br /><br />a = """He said - "I'll be back" and we waited"""<br /><br />install_path = r'C:\backup\remote\network\temp\assorted'<br />unicode_data = u'Hello world'<br />---------------------------------------------------------<br /><b>String operators</b><br />----------------<br />&nbsp; %&nbsp; - String format operator<br />&nbsp; +&nbsp; - String concatenation (from sequence)<br />&nbsp; *&nbsp; - String repetition (from sequence)<br />&nbsp; [] - String index operator (from sequence)<br />&nbsp;====<br /><br /><b>&nbsp;oop test</b><br /><br />&nbsp;from __future__ import print_function<br /><br />class Car:<br />&nbsp; &nbsp; def __init__(self, name):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.name = name<br /><br />&nbsp; &nbsp; @staticmethod<br />&nbsp; &nbsp; def sell():<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Sold this car...")<br /><br />&nbsp; &nbsp; @classmethod<br />&nbsp; &nbsp; def count(c):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("c =", c)<br /><br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Driving", self.name)<br /><br />c = Car("Honda")<br />c.drive()<br />c.sell()<br />Car.sell()<br />c.count()<br />Car.count()<br /><br />Driving Honda<br />Sold this car...<br />Sold this car...<br />c = <class main__.car=""></class><br />c = <class main__.car=""></class><br />=====<br /><br /><b>Performance check</b><br /><br />"""<br />A simple python program to test CPU performance by<br />generating a series of prime numbers<br />"""<br />from __future__ import print_function<br />import sys<br />if sys.version_info[0] == 2:<br />&nbsp; &nbsp; from __builtin__ import xrange as range<br /><br />NUM_PRIMES = 100000<br /><br />def is_prime(number):<br />&nbsp; &nbsp; "Returns True if 'number' is prime"<br />&nbsp; &nbsp; limit = int(number ** 0.5) + 1<br />&nbsp; &nbsp; for i in range(2, limit):<br />&nbsp; &nbsp; &nbsp; &nbsp; if number % i == 0:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return False<br />&nbsp; &nbsp; return True<br /><br />def gen_prime(num):<br />&nbsp; &nbsp; "Generates first 'num' series of prime numbers"<br />&nbsp; &nbsp; i = 2<br />&nbsp; &nbsp; while num:<br />&nbsp; &nbsp; &nbsp; &nbsp; if is_prime(i):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(i)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; num -= 1<br />&nbsp; &nbsp; &nbsp; &nbsp; i += 1<br /><br />from time import time<br /><br />print("Generating %d prime numbers..." % NUM_PRIMES)<br />start = time()<br />gen_prime(NUM_PRIMES)<br />duration = time() - start<br />print("gen_prime(%d) took %f seconds" % (NUM_PRIMES, duration))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />gen_prime(100000) took 12.242300 seconds<br />=====<br /><br /><b>list vs tuple vs set&nbsp;</b><br />from timeit import timeit<br />from sys import argv<br /><br />sample_size = int(argv[1]) if len(argv) &gt; 1 else 1000<br /><br />num_iters = 100000<br />datatypes = "tuple", "list", "set"<br /><br />setup_code = """<br />from random import randint<br />a = {datatype}(range({limit}))<br />"""<br />stmt_code = "randint(0, {limit}) in a"<br /><br />for dt in datatypes:<br />&nbsp; &nbsp; duration = timeit(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setup=setup_code.format(datatype=dt, limit=sample_size),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stmt=stmt_code.format(limit=sample_size),<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; number=num_iters)<br /><br />&nbsp; &nbsp; print("Searching for a random element in {} sized {} took {} seconds".format(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sample_size, dt, duration))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /><b>##output&nbsp; &nbsp;</b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />Searching for a random element in 1000 sized tuple took 0.7152920619992074 seconds<br />Searching for a random element in 1000 sized list took 0.737770362989977 seconds<br />Searching for a random element in 1000 sized set took 0.14120669901603833 seconds&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ====<br /><b><br /></b><b>Thread performance</b><br />from __future__ import print_function<br />from threading import Thread<br /><br />from performance import profile_time, print_log<br />import sys<br /><br />if sys.version_info[0] == 2:<br />&nbsp; &nbsp; range = xrange<br /><br />def worker(w):<br />&nbsp; &nbsp; y = 0<br />&nbsp; &nbsp; print("Starting worker: {}\n".format(w), end="")<br />&nbsp; &nbsp; for i in range(1000):<br />&nbsp; &nbsp; &nbsp; &nbsp; for j in range(10000):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y += i*j<br />&nbsp; &nbsp; print("Worker {} complete: {}\n".format(w, y), end="")<br /><br />@profile_time<br />def start_workers():<br />&nbsp; &nbsp; pool = { }<br />&nbsp; &nbsp; for i in range(16):<br />&nbsp; &nbsp; &nbsp; &nbsp; pool[i] = Thread(target=worker, args=(i,))<br />&nbsp; &nbsp; &nbsp; &nbsp; pool[i].start()<br />&nbsp; &nbsp; print("Created 16 workers...\n", end="")<br /><br />&nbsp; &nbsp; for i in range(16):<br />&nbsp; &nbsp; &nbsp; &nbsp; pool[i].join()<br />&nbsp; &nbsp; print("All workers complete...\n", end="")<br /><br />start_workers()<br /><br />print_log()<br />===<br /><br /><b>read struct</b><br />from __future__ import print_function<br />import struct<br /><br />silly_data_format = 'ich64s'<br />with open("silly_data.dat", "rb") as source:<br />&nbsp; &nbsp; data = struct.unpack(silly_data_format, source.read())<br />&nbsp; &nbsp; print(data)<br /><br /><b>#output</b><br />(42, b'a', 67, b"hello world from the 'C'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")<br />=====<br /><br /><b>read line&nbsp;</b><br /><br />import readline<br /><br />while True:<br />&nbsp; &nbsp; line = input("Enter a line: ")<br />&nbsp; &nbsp; print(line)&nbsp; <br />===<br /><br /><b>local vs global</b><br />a = 10<br />def foo():<br />&nbsp; &nbsp; a = 20<br />&nbsp; &nbsp; print("In foo: a =", a)<br />&nbsp; &nbsp; print(globals())<br />&nbsp; &nbsp; print("-" * 30)<br />&nbsp; &nbsp; print(locals())<br />&nbsp; &nbsp; globals()['a'] = 40<br /><br />foo()<br />print("In main: a =", a)<br /><br /><b>##output</b><br />In foo: a = 20<br />{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external .sourcefileloader="" 0x10821f780="" at="" object="">, '__spec__': None, '__annotations__': {}, '__builtins__': <module built-in="" builtins="">, '__file__': 's1.py', '__cached__': None, 'a': 10, 'foo': <function 0x107f7de18="" at="" foo="">}</function></module></_frozen_importlib_external><br />------------------------------<br />{'a': 20}<br />In main: a = 40<br />====<br /><b><br /></b><b>##scope oo</b><br />color = "white"<br /><br />def start():<br />&nbsp; &nbsp; print("Started program...")<br /><br />class Car:<br />&nbsp; &nbsp; color = "red"<br /><br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.color = "green"<br /><br />&nbsp; &nbsp; def start(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Started car...")<br /><br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; start()<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Driving a", color, "car")<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car.color =", Car.color)<br />&nbsp; &nbsp; &nbsp; &nbsp; print("self.color =", self.color)<br /><br />c = Car()<br />c.drive()<br /><br /><b>##output</b><br />Started program...<br />Driving a white car<br />Car.color = red<br />self.color = green&nbsp; <br />=====<br /><br />a = 10<br /><br />def foo():<br />&nbsp; &nbsp; print("In foo: a =", a)<br />&nbsp; &nbsp; a = 40<br /><br />foo()<br />print("In main: a =", a)<br /><br />##output<br />Traceback (most recent call last):<br />&nbsp; File "scope.py", line 7, in <module></module><br />&nbsp; &nbsp; foo()<br />&nbsp; File "scope.py", line 4, in foo<br />&nbsp; &nbsp; print("In foo: a =", a)<br />UnboundLocalError: local variable 'a' referenced before assignment<br />====<br /><br />from __future__ import print_function<br /><br />a = 10<br /><br />def foo():<br />&nbsp; &nbsp; global a<br />&nbsp; &nbsp; print("In foo: a =", a)<br />&nbsp; &nbsp; a = 20<br /><br />foo()<br />print("In main: a =", a)<br /><br /><b>##output&nbsp;</b><br />In foo: a = 10<br />In main: a = 20<br />===<br /><br />a = [10, 20, 30]<br /><br />def foo():<br />&nbsp; &nbsp; print("In foo: a =", a)<br />&nbsp; &nbsp; a[0] = 100<br /><br />foo()<br />print("In main: a =", a)<br /><br /><b>##output</b><br />In foo: a = [10, 20, 30]<br />In main: a = [100, 20, 30]<br />====<br /><br />color = "white"<br /><br />def start():<br />&nbsp; &nbsp; print("Starting program...")<br /><br />class Car:<br />&nbsp; &nbsp; color = "blue"<br /><br />&nbsp; &nbsp; def __init__(s):<br />&nbsp; &nbsp; &nbsp; &nbsp; s.color = "green"<br /><br />&nbsp; &nbsp; def start(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Starting car...")<br /><br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.start()<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Driving a", color, "car")<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car.color =", Car.color)<br />&nbsp; &nbsp; &nbsp; &nbsp; print("self.color =", self.color)<br /><br />c = Car()<br />c.drive()<br /><br />print(color)<br />print(Car.color)<br />print(c.color)<br /><br /><b>##output</b><br />Starting car...<br />Driving a white car<br />Car.color = blue<br />self.color = green<br />white<br />blue<br />green<br />=====<br /><br />a = [10, 20, 30]<br />b = [40, 50, 60]<br /><br />from itertools import chain<br /><br />for i in chain(a, b):<br />&nbsp; &nbsp; print(i)<br /><br /><b>##output</b><br />10<br />20<br />30<br />40<br />50<br />60<br />====<br /><br /><b>#print table</b><br /><br />num = int(input("Enter a number: "))<br />for i in 1, 2, 3, 4, 5, 6, 7, 8, 9, 10:<br />&nbsp; &nbsp; print(num, "x", i, "=", num*i)<br />&nbsp; <br /><b>##output</b><br />Enter a number: 5<br />5 x 1 = 5<br />5 x 2 = 10<br />5 x 3 = 15<br />5 x 4 = 20<br />5 x 5 = 25<br />5 x 6 = 30<br />5 x 7 = 35<br />5 x 8 = 40<br />5 x 9 = 45<br />5 x 10 = 50<br />====<br /><br />print("Hello world")<br />name = "John"<br />print("Name is {}".format(name))<br />print("Square of 2 is", square(2))<br /><br />def square(x): return x*x<br />===<br /><br />from foo import square<br />print("square of 9 is", square(9))<br />====<br /><br />color = "white"<br /><br />class Car:<br />&nbsp; &nbsp; color = "red"<br /><br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; self.color = "green"<br /><br />&nbsp; &nbsp; def drive(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Driving a", color, "car")<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car.color =", Car.color)<br />&nbsp; &nbsp; &nbsp; &nbsp; print("self.color =", self.color)<br /><br />c = Car()<br />c.drive()<br /><br />Driving a white car<br />Car.color red<br />self.color =&nbsp; green<br />=====<br /><br /><b>chaining</b><br />a = [10, 20, 30, 40]<br />b = [50, 60, 70, 80]<br />from itertools import chain<br /><br />for i in chain(a, b): print i<br />====<br /><br /><b>cyclic reference</b><br /><br />class Car:<br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car object created...")<br /><br />&nbsp; &nbsp; def __del__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car object destroyed...")<br /><br />class Person:<br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Person object created...")<br /><br />&nbsp; &nbsp; def __del__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Person object destroyed...")<br /><br />p = Person()<br />c = Car()<br />c.owner = p<br />p.owns = c<br /><br />print("Created car and person...")<br />del c<br />del p<br />print("Variables c and p deleted...")<br />import gc<br />print(gc.collect())<br /><br /><b>##output</b><br />Person object created...<br />Car object created...<br />Created car and person...<br />Variables c and p deleted...<br />Person object destroyed...<br />Car object destroyed...<br />4<br />=========<br /><b><br /></b><b>delete&nbsp;</b><br /><br />class Person:<br /><br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("User object created...")<br /><br />&nbsp; &nbsp; def __del__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("User object destroyed...")<br /><br />class Car:<br /><br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car object created...")<br /><br />&nbsp; &nbsp; def __del__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car object destroyed...")<br /><br />p = Person()<br />c = Car()<br /><br />p.owns = c<br />c.owner = p<br /><br />print("Car and Person object created...")<br /><br /><b>#output</b><br />User object created...<br />Car object created...<br />Car and Person object created...<br />User object destroyed...<br />Car object destroyed...<br />=======<br /><br /><b>dict:</b><br />user_info = dict(name="John",<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;role="Admin",<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dept="IT",<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;city="Bengaluru")<br /><br />for key, value in user_info.items():<br />&nbsp; &nbsp; print("{} -&gt; {}".format(key, value))<br /><br />#or<br />user_info = {"name": "nawraj","role": "Engineer","dept": "Eng"}<br /><br />for key, value in user_info.items():<br /><span style="white-space: pre;"> </span>print("{} -&gt; {}".format(key, value))<br /><span style="white-space: pre;"> </span><br />=====<br /><br /><b>duck typing</b><br /><br />a = [10, 20, 30]<br />b = (10, 20, 30)<br /><br />def c():<br />&nbsp; &nbsp; print("Hello world")<br /><br />class d:<br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Created an object...")<br /><br />objs = a, b, c, d<br /><br />print(objs)<br /><br />def run(tasks):<br />&nbsp; &nbsp; for t in tasks:<br />&nbsp; &nbsp; &nbsp; &nbsp; if callable(t): t()<br /><br />run(objs)<br /><br /><b>#output</b><br />([10, 20, 30], (10, 20, 30), <function 0x10d551e18="" at="" c="">, <class main__.d="">)</class></function><br />Hello world<br />Created an object...<br />====<br /><br /><b>findall&nbsp;</b><br /><br />"""<br />Preliminary exercise<br />====================<br />Implement the findall() function below that must return a list<br />of indices all occurrence of a substring found in a string<br />(both passed as arguments to the function).<br /><br />Example usage:<br />--------------<br />&nbsp; &nbsp;&gt;&gt;&gt; quote = '''<br />&nbsp; &nbsp;... When I see a bird<br />&nbsp; &nbsp;... that walks like a duck<br />&nbsp; &nbsp;... and swims like a duck<br />&nbsp; &nbsp;... and quacks like a duck,<br />&nbsp; &nbsp;... I call that bird a duck<br />&nbsp; &nbsp;... '''<br /><br />&nbsp; &nbsp;&gt;&gt;&gt; findall(quote, "duck")<br />&nbsp; &nbsp;[37, 59, 82, 107]<br /><br />"""<br /><br />def findall(main_string: str, sub_string: str) -&gt; list:<br />&nbsp; &nbsp; """<br />&nbsp; &nbsp; Returns a list of indices of each occurrence of<br />&nbsp; &nbsp; sub_string in main_string<br /><br />&nbsp; &nbsp; Example usage:<br />&nbsp; &nbsp; --------------<br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; poem = '''<br />&nbsp; &nbsp; &nbsp; &nbsp; ... A fly and flea flew into a flue,<br />&nbsp; &nbsp; &nbsp; &nbsp; ... said the fly to the flea 'what shall we do ?'<br />&nbsp; &nbsp; &nbsp; &nbsp; ... 'let us fly' said the flea<br />&nbsp; &nbsp; &nbsp; &nbsp; ... and said the fly 'let us flee'<br />&nbsp; &nbsp; &nbsp; &nbsp; ... and so they flew through a flaw in to the flue.<br />&nbsp; &nbsp; &nbsp; &nbsp; ... '''<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; findall(poem, 'fly')<br />&nbsp; &nbsp; &nbsp; &nbsp; [3, 43, 88, 120]<br /><br />&nbsp; &nbsp; """<br />&nbsp; &nbsp; indices = []<br />&nbsp; &nbsp; i = 0<br />&nbsp; &nbsp; while True:<br />&nbsp; &nbsp; &nbsp; &nbsp; i = main_string.find(sub_string, i)<br />&nbsp; &nbsp; &nbsp; &nbsp; if i == -1: break<br />&nbsp; &nbsp; &nbsp; &nbsp; indices.append(i)<br />&nbsp; &nbsp; &nbsp; &nbsp; i += len(sub_string)<br />&nbsp; &nbsp; return indices<br /><br />if __name__ == '__main__':<br />&nbsp; &nbsp; import doctest<br />&nbsp; &nbsp; doctest.testmod()<br />&nbsp; &nbsp; # Running this program using 'python3 findall.py' should<br />&nbsp; &nbsp; # ideally pass all tests in the doctest - on implementation<br />&nbsp; &nbsp; # of findall() function<br />======<br /><br />name = "smith"<br /><br />class User:<br />&nbsp; &nbsp; """<br />&nbsp; &nbsp; A simple User class<br /><br />&nbsp; &nbsp; eoiwru iowe uriowue rio wuerio<br />&nbsp; &nbsp; sdlj fskldj fklsdj flksdjfkls<br /><br />&nbsp; &nbsp; """<br />&nbsp; &nbsp; def __init__(self, name):<br />&nbsp; &nbsp; &nbsp; &nbsp; """<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Create a new user object with 'name' passed<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; as argument.<br />&nbsp; &nbsp; &nbsp; &nbsp; """<br />&nbsp; &nbsp; &nbsp; &nbsp; self.name = name<br /><br />&nbsp; &nbsp; def greet(self): print(self.name, "says Hello!")<br /><br />&nbsp; &nbsp; def welcome(): print("Welcome to Python...")<br /><br />def square(x):<br />&nbsp; &nbsp; "Returns square of argument x."<br />&nbsp; &nbsp; return x*x<br /><br />if __name__ == '__main__':<br />&nbsp; &nbsp; print("Main program running...")<br />&nbsp; &nbsp; print("a =", a)<br />&nbsp; &nbsp; print("name =", name)<br />&nbsp; &nbsp; print("square(2) =", square(2))<br />&nbsp; &nbsp; u = User("John")<br />&nbsp; &nbsp; u.greet()<br /><br />##otuput&nbsp; <br />Main program running...<br />a = 100<br />name = smith<br />square(2) = 4<br />John says Hello!&nbsp; &nbsp;&nbsp;<span style="white-space: pre;"> </span><br />=========<br /><br /><b>for loop implementation</b><br /><br />a = [10, 20, 30, 40, 50]<br /><br />#for i in a: print i,<br /><br />iterator = iter(a)<br />if hasattr(a, '__getitem__') and hasattr(a, '__len__'):<br />&nbsp; &nbsp; length = len(a)<br />&nbsp; &nbsp; index = 0<br />&nbsp; &nbsp; while index &lt; length:<br />&nbsp; &nbsp; &nbsp; &nbsp; i = a[index]<br />&nbsp; &nbsp; &nbsp; &nbsp; index += 1<br /><br />if hasattr(a, '__len__'):&nbsp; # For fixed-length iterable objects<br />&nbsp; &nbsp; length = len(a)&nbsp; &nbsp; &nbsp; &nbsp; # (a.k.a collections/containers)<br />&nbsp; &nbsp; while length:<br />&nbsp; &nbsp; &nbsp; &nbsp; i = next(iterator)<br />&nbsp; &nbsp; &nbsp; &nbsp; print (i),&nbsp; # 'for' loop body<br />&nbsp; &nbsp; &nbsp; &nbsp; length -= 1<br /><br />else:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # For generators/views/non-collection iterables<br />&nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; while True:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = next(iterator)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print (i),&nbsp; # 'for' loop body<br />&nbsp; &nbsp; except StopIteration:<br />&nbsp; &nbsp; &nbsp; &nbsp; pass<br /><br /><b>#output</b><br />10<br />20<br />30<br />40<br />50<br />========<br /><br />class Car:<br />&nbsp; &nbsp; def __init__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Created a new car object...")<br /><br />&nbsp; &nbsp; def __del__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Car object is being destroyed!")<br /><br />c1 = Car()<br />c2 = c1<br />c3 = c2<br />print(c1, c2, c3)<br /><br />print("Changing c2...")<br />c2 = 100<br /><br />print("Deleting c1...")<br />del c1<br /><br />print("Changing c3...")<br />c3 = "Hello world"<br /><br />print("End of program...")<br /><br /><b>##output</b><br />Created a new car object...<br /><__main__ .car="" 0x109a13780="" at="" object=""> <__main__ .car="" 0x109a13780="" at="" object=""> <__main__ .car="" 0x109a13780="" at="" object=""></__main__></__main__></__main__><br />Changing c2...<br />Deleting c1...<br />Changing c3...<br />Car object is being destroyed!<br />End of program...<br />=====<br /><br />a = "10"<br /><br />def foo():<br />&nbsp; &nbsp; from builtins import int<br />&nbsp; &nbsp; la = a<br /><br />&nbsp; &nbsp; for i in range(1000000):<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Value of a is", int(la))<br /><br />foo()<br />========<br /><br />def greet():<br />&nbsp; &nbsp; print("Hello world")<br /><br />def greet(user):<br />&nbsp; &nbsp; print("Hello", user)<br /><br />greet("John")<br />greet()<br /><br /><b>##output</b><br />Hello John<br />Traceback (most recent call last):<br />&nbsp; File "greet_bad.py", line 8, in <module></module><br />&nbsp; &nbsp; greet()<br />TypeError: greet() missing 1 required positional argument: 'user'<br />====<br /><br />def greet(user=None):<br />&nbsp; &nbsp; if user is None:<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Hello world")<br />&nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Hello", user)<br /><br />greet("John")<br />greet()<br /><br />Hello John<br />Hello world<br /><br />========<br /><b>use of sep</b><br /><br />print("Hello world", "Another string", sep="")<br /><br />## sep is the separator used between multiple values when printing. The default is a space (sep=' ')<br />===<br /><br /><b>use fo end</b><br /><br />print("Hello world", end="\t")<br /><br /># Python’s print() function comes with a parameter called ‘end’. By default, the value of this parameter is ‘\n’, i.e. the new line character. You can end a print statement with any character/string using this parameter<br />===<br /><br /><b>Infinite loop</b><br />from itertools import count<br />for i in count(10, 2):<br />&nbsp; &nbsp; print(i)<br /><br /># count(start=0, step=1) --&gt; count object<br /><br />from itertools import count<br /><br />i = 0<br />while True:<br />&nbsp; &nbsp; print(i)<br />&nbsp; &nbsp; i += 1<br /><br />for i in count():<br />&nbsp; &nbsp; print(i)<br />====<br /><br /><b>module test</b><br /><br />def foo():<br />&nbsp; &nbsp; from time import ctime<br />&nbsp; &nbsp; print("Time now is", ctime())<br /><br />def bar():<br />&nbsp; &nbsp; from time import ctime<br />&nbsp; &nbsp; print("Time now in bar is", ctime())<br /><br />foo()<br />bar()<br /><br />Time now is Fri Oct 20 10:12:17 2017<br />Time now in bar is Fri Oct 20 10:12:17 2017<br /><br />## ctime : Convert a time in seconds since the Epoch to a string in local time.<br />&nbsp; &nbsp; This is equivalent to asctime(localtime(seconds)). When the time tuple is<br />&nbsp; &nbsp; not present, current time as returned by localtime() is used.<br />&nbsp; <br /><br />&nbsp; <br /><br /><br /><br /><br /><br /><br /><span style="white-space: pre;"> </span><br /><span style="white-space: pre;"> </span><br /><br /><br /><br /><br /><br /><br /></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com1tag:blogger.com,1999:blog-6880492769470667099.post-47067958398200420972017-10-08T12:47:00.002+05:302018-08-14T22:59:20.523+05:30Linux Command Line<div dir="ltr" style="text-align: left;" trbidi="on"><b>Terminal usage:</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ ls -lh<br />total 67992<br />-rw-r--r--@&nbsp; 1 nawlekha&nbsp; staff&nbsp; &nbsp; 19M Mar&nbsp; 2&nbsp; 2017 CodeSchool-TryPython.pdf<br />-rw-r--r--&nbsp; &nbsp;1 nawlekha&nbsp; staff&nbsp; &nbsp;210B Sep 21 18:01 LEGB.py<br />drwxr-xr-x&nbsp; 19 nawlekha&nbsp; staff&nbsp; &nbsp;646B Feb 28&nbsp; 2017 PyATS online sessions/<br />drwx------@ 45 nawlekha&nbsp; staff&nbsp; &nbsp;1.5K Jun 19 10:25 Python 3 for begineers<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ ls -l /var/log<br />total 73464<br />drwxr-xr-x&nbsp; &nbsp;3 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;102B Apr 13 21:14 Bluetooth/<br />-rw-r--r--@&nbsp; 1 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 12B Apr 13 21:13 CDIS.custom<br />drwxr-xr-x&nbsp; &nbsp;2 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 68B Aug&nbsp; 6&nbsp; 2016 CoreDuet/<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ ls -l -a -h /var/log or ls -lah<br />total 73464<br />drwxr-xr-x&nbsp; 62 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.1K Oct&nbsp; 5 17:37 ./<br />drwxr-xr-x&nbsp; 28 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;952B Jul 21 17:29 ../<br />drwxr-xr-x&nbsp; &nbsp;3 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;102B Apr 13 21:14 Bluetooth/<br />-rw-r--r--@&nbsp; 1 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 12B Apr 13 21:13 CDIS.custom<br />drwxr-xr-x&nbsp; &nbsp;2 root&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wheel&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 68B Aug&nbsp; 6&nbsp; 2016 CoreDuet/<br /><br />Ctrl + A = move to beginning<br />Ctrl + E = move to end<br />Clear =&gt; clear terminal<br /><br />Ctrl + U =&gt; deletes from cursor to beginning of line<br /><br />Ctrl + K =&gt; deletes from cursor to end of line<br /><br />Ctrl+Shift+C =&gt; Copy to clipboard<br /><br />Ctrl+ Shift+V =&gt; Paste to clipboard<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ man ls<br /><br />~ means home folder<br /><b><br /></b><b>## to access folder name having space</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ cd Python training_doc<br />-bash: cd: Python: No such file or directory<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ cd Python\ training_doc<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS/Python training_doc$<br /><br /><b>## to list all folders under directory</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ ls -R Python\ training_doc<br />Foundations of Python Network&nbsp; Programming, 3rd Edition.pdf&nbsp; byte_of_python.pdf<br />PY_diff.txt&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dive-into-python3.pdf<br />Python&nbsp; Scripting_new.pptx&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thinkpython.pdf<br />apr-24.txt<br /><br /><b>## to represent parent directory of current directory</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ cd ..<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop$<br /><br /><b>## to move back between folder</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ cd -<br />/Users/nawlekha/Desktop/pyATs<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATs$<br /><br /><b>## this will take you from wherever you are to home folder</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATs$ cd<br />nawlekha@NAWLEKHA-M-Q1GZ:~$<br /><b><br /></b><b>## to create and remove directory</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mkdir new_folder<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ rmdir new_folder<br /><br /><b>## in order to remove, folder it should be empty</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mkdir new_folder<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mkdir new_folder/hello<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ rmdir new_folder<br />rmdir: new_folder: Directory not empty<br /><br />for this we can do rm -r ## delete recursively<br /><br /><b>## move file to other dir and also to rename files</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ vi forfun.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mv forfun.txt new_folder/<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ ls for*<br />ls: for*: No such file or directory<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS/new_folder$ ls<br />forfun.txt&nbsp; hello/<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mv new_folder/forfun.txt new_folder/funny.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ cd new_folder/<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS/new_folder$ ls<br />funny.txt&nbsp; hello/<br /><br /><b>## to move folder to current directory</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mv new_folder/funny.txt .<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ ls fu*<br />funny.txt<br /><br /><b>## to move all .txt files to new folder</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mv *.txt new_folder/<br /><b><br /></b><b>## to move back all files to current dir</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ mv new_folder/* .<br /><br /><b>## use of ? to delete files. this will delete file name with funny followed by any single character</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ cp funny.txt funny1.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ cp funny.txt funny2.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ rm funny?.txt<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ ls fun*<br />funny.txt<br /><br /><b>## find all files in current directory search based on name</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ find . -name "*.txt"<br />./apr-24.txt<br />./funny.txt<br />./Python 3 for begineers/12.3/employees.txt<br />./python training.txt<br />./Python training_doc/apr-24.txt<br />./Python training_doc/PY_diff.txt<br />./python_training_examples/one.txt<br />./python_training_examples/output.txt<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ find . -name "PyATS*"<br />./PyATS online sessions<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ find . -name "*folio*"<br />./portfolio.csv<br />./portfolio1.csv<br /><br /><b>## to search in different folder</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ find ~/ -name "*folio*"<br />/Users/nawlekha//Desktop/pyATS/portfolio.csv<br />/Users/nawlekha//Desktop/pyATS/portfolio1.csv<br />find: /Users/nawlekha//Library/Caches/com.cisco.Jabber/com.apple.opencl: Permission denied<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$<br /><b><br /></b><b>## to gain root permission we can use sudo. For first time it will ask for password but there is some grace time within which it won’t prompt for password</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ sudo ls /root<br />Password: ## user password<br />ls: /root: No such file or directory<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ sudo ls<br />.DS_Store<span style="white-space: pre;"> </span>missing.csv<br />CodeSchool-TryPython.pdf<span style="white-space: pre;"> </span>new_folder<br /><br /><b>## to give up privilege</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ sudo -k<br /><br /><b>## if you want to work as root</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pyATS$ su root<br />Password:<br /><br />Now prompt will change to #<br /><br />To switch back to $ prompt type exit<br /><br /><b>## Octal file permissions</b><br />file rwxrwxrwx<br />first rwx represent user or owner of the file<br />2nd rwx represent group the owner is the member of<br />3rd rwx represent all other group the owner is not the member of<br /><br />user rwx 421 = 7<br />group rx&nbsp; 41 = 5<br />Other r&nbsp; &nbsp; 4&nbsp; = 4<br /><br /><b>## we can change permission of file using chmod command</b><br />two ways to do so<br />-&gt; octal (e.g. 755 644 777)<br />-&gt; symbolic (e.g. a=r, g+w, and o-x)<br /><br />user = u ,<br />to provide user read, write and execute permission: chmod u+rwx<br />group = g,<br />to provide group read permission: chmod g=r<br />others = o,<br />to remove read, write and execute from others : chmod o-rwx<br />All = a<br /><br />+ adds permission; - removes permission<br />= adds permission but removes others<br /><br /><b>Comparision of octal and symbolic values</b><br /><br />777 or a+rwx : rwxrwxrwx<br />755 or u+rwx,g=rx,o=rx : rwx-xr-xr<br />644 or u=rw,g=r,o=r : rw-r- -r- -<br />700 or u=rwx,g-rwx,o-rwx : rwx- - - - - -<br /><br /><b>## to run executable file on command line</b><br />./file.sh<br /><br /><b>==&gt; executable means runs on its own without having to be loaded by other program first</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ ./LEGB.py<br />-bash: ./LEGB.py: Permission denied<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ ls -lh LEGB.py<br />-rw-r--r--&nbsp; 1 nawlekha&nbsp; staff&nbsp; &nbsp;210B Sep 21 18:01 LEGB.py<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ python3 LEGB.py<br />outer x<br />outer x<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$<br /><br /><b>## still i was able to run file using python3 because it is not run on itself. it is run by other program</b><br /><b><br /></b><b>## let’s provide read, write and execute permission to user</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ chmod 744 LEGB.py<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ ls -lh LEGB.py<br />-rwxr--r--&nbsp; 1 nawlekha&nbsp; staff&nbsp; &nbsp;210B Sep 21 18:01 LEGB.py*<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ ./LEGB.py<br />./LEGB.py: line 4:<br />LEGB<br />Local, Enclosing, Global, Built-in<br />: command not found<br />./LEGB.py: line 12: syntax error near unexpected token `('<br />./LEGB.py: line 12: `def outer():'<br /><br /><b>## let’s remove read permission for user</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ chmod 244 LEGB.py or chmod u-r LEGB.py<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ cat LEGB.py<br />cat: LEGB.py: Permission denied<br />## let’s provide read permission again<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ chmod 755 LEGB.py<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ cat LEGB.py<br />'''<br />LEGB<br />Local, Enclosing, Global, Built-in<br />'''<br /><br />#import builtins<br />#print(dir(builtins))<br /><br /><br />#x = 'global x'<br /><br />def outer():<br /><span style="white-space: pre;"> </span>x = 'outer x'<br /><span style="white-space: pre;"> </span><br /><span style="white-space: pre;"> </span>def inner():<br /><span style="white-space: pre;"> </span>#x = 'inner x'<br /><span style="white-space: pre;"> </span>print(x)<br /><span style="white-space: pre;"> </span>inner()<br /><span style="white-space: pre;"> </span>print(x)<br /><br />outer()<br /><br /><b>## when a user create a file in home directory, it starts with 664 permission</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ touch newfile<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ ls -lh newfile<br />-rw-rw-r—&nbsp; 1 nawlekha&nbsp; staff&nbsp; &nbsp; &nbsp;0B Oct&nbsp; 5 19:46 newfile<br /><br /><b>## we can change the ownership of the file</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ sudo chmod root newfile<br />## after changing ownership we won’t be able to write to it<br />"newfile" [readonly] 1L, 8C<br /><br /><b>## lets move back the ownership. Now i am able to write to file</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ sudo chown nawlekha newfile<br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ vi newfile<br /><br /><b>## for changing group ownership we will use chgrp</b><br /><br /><b>## command to print whatever you give to it</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ echo "hello"<br />hello<br /><br /><b>## use of pipeline</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ echo "hello" | wc<br />&nbsp; &nbsp; &nbsp; &nbsp;1&nbsp; &nbsp; &nbsp; &nbsp;1&nbsp; &nbsp; &nbsp; &nbsp;6<br />==&gt; one line of text, one word and six character<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/DEsktop/pYATS$ echo "hello world from the command line" | wc<br />&nbsp; &nbsp; &nbsp; &nbsp;1&nbsp; &nbsp; &nbsp; &nbsp;6&nbsp; &nbsp; &nbsp; 34<br /><br /><b>## Cat&nbsp;</b><br />concatenate and print files<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ cat comment.py<br /><br /><b>## to see first 10 and last 10 lines of a file</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ head comment.py<br />print('Hi i am Nawraj')<br /><br />if False:<br />&nbsp; &nbsp; print('This code will not execute')<br /><br /><br />if True:<br />&nbsp; &nbsp; print('Hello nawraj')<br /><br />"""<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ tail comment.py<br /><br />#or<br /><br />if False: """<br />def sum(x,y):<br />&nbsp; &nbsp; return(x+y)<br /><br />print(sum(1,2))<br />"""<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br /><b>## we can also customise it.&nbsp; this will print 1st 5 lines of a file</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ head -n 5 comment.py<br />print('Hi i am Nawraj')<br /><br />if False:<br />&nbsp; &nbsp; print('This code will not execute')<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br /><b>## last 3 lines of file</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ tail -n 3 comment.py<br />print(sum(1,2))<br />"""<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ cat comment.py | cat -n | tail -n 5<br />&nbsp; &nbsp; 21<span style="white-space: pre;"> </span>&nbsp; &nbsp; return(x+y)<br />&nbsp; &nbsp; 22<span style="white-space: pre;"> </span><br />&nbsp; &nbsp; 23<span style="white-space: pre;"> </span>print(sum(1,2))<br />&nbsp; &nbsp; 24<span style="white-space: pre;"> </span>"""<br />&nbsp; &nbsp; 25<span style="white-space: pre;"> </span><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ cat comment.py | tail -n 5 | cat -n<br />&nbsp; &nbsp; &nbsp;1<span style="white-space: pre;"> </span>&nbsp; &nbsp; return(x+y)<br />&nbsp; &nbsp; &nbsp;2<span style="white-space: pre;"> </span><br />&nbsp; &nbsp; &nbsp;3<span style="white-space: pre;"> </span>print(sum(1,2))<br />&nbsp; &nbsp; &nbsp;4<span style="white-space: pre;"> </span>"""<br />&nbsp; &nbsp; &nbsp;5<span style="white-space: pre;"> </span><br /><br /><b>## to view large files</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ less comment.py<br />press q to quit<br /><br /><b>## to filter piece of information</b><br />grep is used to search files for text that matches a given pattern<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ grep "sum" comment.py<br />def sum(x,y):<br />print(sum(1,2))<br />def sum(x,y):<br />print(sum(1,2))<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ grep -n "sum" comment.py<br />11:def sum(x,y):<br />14:print(sum(1,2))<br />20:def sum(x,y):<br />23:print(sum(1,2))<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><b><br /></b><b>## grep is case sensitive</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ grep -n "Sum" comment.py<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br /><b>## for case in-sensitive we can use -i</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ grep -i "nawraj" comment.py<br />print('Hi i am Nawraj')<br />&nbsp; &nbsp; print('Hello nawraj')<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br /><b>## to omit lines which we don’t want to see</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ grep -vi "sum" comment.py<br />print('Hi i am Nawraj')<br /><br />if False:<br />&nbsp; &nbsp; print('This code will not execute')<br /><br /><br />if True:<br />&nbsp; &nbsp; print('Hello nawraj')<br /><br />"""<br />&nbsp; &nbsp; return(x+y)<br /><br />"""<br /><br />#or<br /><br />if False: """<br />&nbsp; &nbsp; return(x+y)<br /><br />"""<br /><b><br /></b><b>## for regex we can use -E. To fetch he occurrence of letter "hijk"</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ grep -E "[hijk]" comment.py<br />print('Hi i am Nawraj')<br />if False:<br />&nbsp; &nbsp; print('This code will not execute')<br />if True:<br />&nbsp; &nbsp; print('Hello nawraj')<br />print(sum(1,2))<br />if False: """<br />print(sum(1,2))<br /><br /><b>## 6 or more any word character</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ grep -E "\w{6,}" comment.py<br />print('Hi i am Nawraj')<br />&nbsp; &nbsp; print('This code will not execute')<br />&nbsp; &nbsp; print('Hello nawraj')<br />&nbsp; &nbsp; return(x+y)<br />&nbsp; &nbsp; return(x+y)<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br /><b>## awk and sed</b><br />tools to extract or modify text from a file or stream<br /><b><br /></b><b>## print values from 2nd column</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ awk '{print $2}' apr-24.txt<br /><br /><b>## to sort output based on numbers</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ awk '{print $2 "\t" $1}' apr-24.txt | sort -n<br /><br /><b>## while awk is used for extracting data, sed is used for modify data</b><br />#every occurrence of you is replaced by him<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ sed s/you/him/ funny.txt<br />hello how r him.<br />i am looking for him.<br /><br /><b>## sort</b><br /><b>#by default sort is based on the 1st character.</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ sort funny.txt<br />ahh !! i forgot to call you.<br />hello how r you.<br />i am looking for you.<br /><br /><b># we can also do sort based on columns and numbers</b><br />## sort based on 2nd column numbers<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ sort -k2n simple.txt<br /><b><br /></b><b>### to remove duplicate entry</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ cat funny.txt<br />hello how r you.<br />i am looking for you.<br />ahh !! i forgot to call you.<br />i am looking for you.<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ sort -u funny.txt<br />ahh !! i forgot to call you.<br />hello how r you.<br />i am looking for you.<br /><br /><b>## to print file in reverse order</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ rev funny.txt<br />&nbsp;.uoy r woh olleh<br />.uoy rof gnikool ma i<br />.uoy llac ot togrof i !! hha<br />.uoy rof gnikool ma i<br /><br /><b>## to change all lower case to upper</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ cat funny.txt | tr [:lower:] [:upper:]<br />HELLO HOW R YOU.<br />I AM LOOKING FOR YOU.<br />AHH !! I FORGOT TO CALL YOU.<br />I AM LOOKING FOR YOU.<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$<br /><br /><b>## we have two editors. One is vi and another is nano</b><br />nano is by default present in MacOS.<br />== to write or save file in nano ctl + o<br />== to exit out of file ctl + x<br />== ctl + v to move down the screen<br />== ctl + y to move up the screen<br />== ctl + a to beginning of line<br />== ctl + e to end of line<br /><br /><b>## tar</b><br />create and manipulate tape archive files<br />.tar<br />.tar.gz<br />.tgz<br />.tar.bz2<br /><br />tar -caf myfiles.tar.gz Exercise\ Files/<br /><br />## Exercise and Files are are folders we want to compress<br /><b><br /></b><b>## to extract tar file</b><br />tar -xf mayflies.tar.gz<br /><br /><b>## Redirection</b><br />(standard input)stdin , keyboard input, descriptor 0<br />srdout, text on screen, 1<br />stderr, Error text on screen , 2<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ ls<br />hello/&nbsp; &nbsp; &nbsp; sample.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ ls 1&gt;filelist.txt<br />## here 1 is stdout<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ cat filelist.txt<br />filelist.txt<br />hello/<br />sample.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$<br /><br />## we can ommit 1 as well<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ ls &gt; filelist2.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ cat filelist2.txt<br />filelist.txt<br />filelist2.txt<br />hello/<br />sample.txt<br /><br /><b>## usage of stdr</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ ls notreal<br />ls: notreal: No such file or directory<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ ls notreal 2&gt; fileslist4.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ cat fileslist4.txt<br />ls: notreal: No such file or directory<br /><br />single “&gt;” will redirect the file<br />double “&gt;&gt;” will append the file<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ cat fileslist4.txt<br />ls: notreal: No such file or directory<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ &gt;fileslist4.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ cat fileslist4.txt<br />## fileslist4 is empty. &gt; has overhidden the file<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ ls &gt; filelist5.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ echo "and some appended text" &gt;&gt; filelist5.txt<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$ cat filelist5.txt<br />filelist.txt<br />filelist2.txt<br />filelist5.txt<br />fileslist4.txt<br />hello/<br />sample.txt<br />and some appended text<br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS/new_folder$<br /><br />Problem: You have received a log file from your admin. In logs there are some breaking attempts by hacker .Your task is<br />1. Extract the log file<br />2. look for invalid user authorisation requests<br />3. Create a file containing the usernames<br /><br /><b>Solution:</b><br />## tar -xvf log.tar.gz<br />## cat auth.log<br />## cat auth.log | grep “input_userauth_request” | awk ‘{print $9}’ | sort -u &gt;&gt; users.txt<br />## cat users.txt<br /><br /><b>## to find which linux distribution you are using</b><br />cat /etc/* -release<br /><br /><b>In mac we should use</b><br />nawlekha@NAWLEKHA-M-Q1GZ:/users/nawlekha/Desktop/pyATS$ uname -a<br />Darwin NAWLEKHA-M-Q1GZ 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64<br /><br />mac oS is not linux it is unix variant<br /><br />## uname -a works in linux too<br /><br /><b>## in linux to see free memory&nbsp;</b><br />free -h<br />cat /proc/cpuinfo<br /><br /><b>## to see space across volumes</b><br />df -h<br /><br /><b>## to see space taken by files and folders</b><br />du -h<br /><br /><b>## “dnf” is used to install software in fedora . It is replacement of yum</b><br />eg. sudo def install nano<br /><br /><b>## in ubuntu we use “apt” to install software</b><br />e.g. sudo apt-get update<br /><br /><b>Quiz.</b><br />1. Select the command that gives you the absolute path of the folder where you are currently working.<br />pwd<br /><br />2. ls -l shows the permissions and ownership of files, among other things.<br />Yes, this istrue.<br /><br />3. What command do you use to create a folder?<br />mkdir<br /><br />4. Which of the following commands copies test1.txt to test2.txt?<br />cp test1.txt test2.txt<br /><br />5. What character do you use with the find command to match any number of characters?<br />*<br /><br />6. What are the two basic user roles in Linux?<br />normal and superuser<br /><br />7. "rwxrw-r--" indicates that the owner of the file can read and write, but not execute the file.<br />Yes, this is false.<br /><br />8. The command line is a text-based interface to type commands and direct text-based input and output to screen, files, and other programs.<br />You’re correct!<br /><br />9. What is the general pattern of a command line statement?<br />command, options, arguments<br /><br />10. What does ~ represent in a command line statement?<br />the user's home folder<br /><br />11.What is the keyboard shortcut to jump to the end of the command line?<br />Ctrl + E<br /><br />12. Which typed statement will show you more information about a particular command?<br />man [commandName]<br /><br />13.What is the core Unix philosophy?<br />Tools should do one thing, and do it well.<br /><br />14. What is the result of this command: echo "command" | wc<br />"1 1 8"<br /><br />15. Select the command that lists the last few lines of a log file.<br />tail log.txt<br /><br />16. The grep command prints the lines of text that match a pattern .<br />You’re correct!<br /><br />17. Which 'awk' command shows the first column of data from a log file?<br />wk '{print $1}' logs.txt<br /><br />18. What are the two modes in Vim?<br />insertion mode and command mode<br /><br />19. You can use ^O to save a file in nano<br />Yes, this istrue.<br /><br />20. Tar files do not offer compression themselves.<br />Yes, this istrue.<br /><br />21. Select the name that has the descriptor of 1.<br />stdout<br /><br />22. Which command help you select lines that have specific text you are looking for?<br />grep<br /><br />23. Write the command that lists the contents of all the files in the systems /etc folder that end with -release.<br />cat /etc/*-release<br /><br />24. This command outputs the RAM value for the local machine<br />free -h<br /><br />25. Which command installs nano on Fedora?<br />sudo dnf install nano<br /><br /><br />Miscellaneous<br /><br />Your assistant needs to print directory stack, what would you suggest?<br />NAWLEKHA-M-N1AJ:bin nawlekha$ dirs<br />/usr/local/bin<br /><br />You have a large text file, and you need to see one page at a time. What will you do?<br />You can achieve the above result by pipeling the output of 'cat file_name.txt' with 'more' command.<br />[root@localhost ~]# cat file_name.txt | more<br /><br />What are daemons?<br />Daemons are services that provide several functions that may not be available under the base operating system. Its<br />main task is to listen for service request and at the same time to act on these requests. After the service is done, it<br />is then disconnected and waits for further requests.<br /><br />You have lots of running jobs, how would you remove all the running processes, without<br />restarting the machine?<br />The Linux command 'disown -r' will remove all the running Processes.<br /><br />A user is new to Linux and he wants to know full list of available commands, what would<br />you suggest him?<br />A command 'compgen -c' will show a<br />full list of available commands.<br />[root@localhost ~]$ compgen -c<br /><br />You need to track events on your system. What will you do?<br />For tracking the events on the system, we need a daemon called syslogd. The syslogd daemon is useful in tracking<br />the information of system and then saving it to specified log files.<br />Running „syslogd„ application in terminal generates log file at the location „/var/log/syslog„. The syslogd application is<br />very useful in troubleshooting Linux sytems. A sample log file looks similar to below.<br /><br />Tell us the difference between Telnet and SSH?<br />Telnet and SSH both are communication protocol which are used to manage remote system. SSH is Secured, which<br />requires exchanging of key opposite of telnet which transmit data in plain text, which means telnet is less secure<br />than SSH.<br /><br />What is the difference between command „ping‟ and „ping6′?<br />Both the commands are same and used for the same purpose except that the fact that ping6 is used with ipv6 IP<br />address<br /><br />You want to search for all the *.tar files in your Home directory and wants to delete all at<br />once. How will you do it?<br />We need to use find command with rm command to delete all “.tar” files.<br /># find /home/ -name '*.tar' | xargs rm -rf<br /><br />Which ports should you open in host firewall for an email server?<br />Open port 110 which is used by the POP3 e-mail protocol.<br />Open port 25 which is used by the SMTP e-mail protocol.<br />Open port 143 which is used by the IMAP e-mail protocol.<br /><br />List out few of the differences between Softlink and Hardlink ?<br />a) Hardlink cannot be created for directories. Hard link can only be created for a file.<br />b) Symbolic links or symlinks can link to a directory.<br />c) Removing the original file that your hard link points to does not remove the hardlink itself; the hardlink still<br />provides the content of the underlying file.<br />d) If you remove the hard link or the symlink itself, the original file will stay intact.<br />e) Removing the original file does not remove the attached symbolic link or symlink, but without the original file, the<br />symlink is useless<br /><br />Differentiate relative path from absolute path<br />Relative path refers to the path relative to the current path. Absolute path, on the other hand, refers to the exact path<br />as referenced from the root directory.<br /><br />What is pid?<br />Pid is short for Process ID. It is used primarily to identify every process that runs on the UNIX system, whether it<br />runs on the foreground or runs at the background. Every pid is considered unique.<br /><br />I want to see how many interfaces (Ethernet cards) are working using single command?<br />Ifconfig<br /><br /><div><br /></div></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com0tag:blogger.com,1999:blog-6880492769470667099.post-32243055217230801482017-10-01T11:18:00.003+05:302017-10-14T13:10:05.004+05:30Python miscellaneous<div dir="ltr" style="text-align: left;" trbidi="on"><div class="p1"><div class="p1">Use Procedural Language (if you want to maintain scripts yourself)</div><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> <br /><div class="p1">- modularity and reusability</div><div class="p1"><br /></div><div class="p1">object oriented.(suitable for large team)</div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1">- individual objects (independent), delegation and concerns,<span class="Apple-converted-space">&nbsp;</span></div><div class="p1"><span class="Apple-converted-space"><br /></span></div><div class="p1">Why python?</div><div class="p1">Implementation of python - Cpython(python written in C) and Pypy (Python written in python)</div><div class="p1"><br /></div><div class="p1">python is slower if we use Cpython but fast with Pypy,<span class="Apple-converted-space">&nbsp;</span></div><div class="p1">code is interpreted while running in python</div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1">Python is easy to maintain. data types in python are limitless</div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1">python3 is dynamic language. that’s why is used popularly. most errors in python occurs in run-time</div><div class="p1">Cpython is official maintained by python author</div><div class="p1">youtube is run on python</div><div class="p1"><span class="Apple-converted-space"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </span></div><div class="p1">Pypy is ongoing program but popular</div><div class="p1"><br /></div><div class="p1"><br /></div><div class="p1">Scripting languages:</div><div class="p1">Go language</div><div class="p1">scala<span class="Apple-converted-space">&nbsp;</span></div><div class="p1">Julia</div><div class="p1">Java</div><div class="p1">Perl</div><div class="p1">Python</div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1">cobol</div><div class="p1">C</div><div class="p1">C++</div><div class="p1"><br /></div><div class="p1">python2:</div><div class="p1">range is inefficient to count large numbers (generate and count) ,called as iterator</div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1">xrange is used for same in python2 (memory efficient) = on the fly, on demand, called as generator</div><div class="p1"><br /></div><div class="p1">xrange is replcaed by range in python3</div><div class="p1"><br /></div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1">all collections have iterable.<span class="Apple-converted-space">&nbsp;</span></div><div class="p1"><span class="Apple-converted-space"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; import sys</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; sys.getsizeof(a)</span></div><div class="p2"><span class="s2">72</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; ## 72 byte</span></div><div class="p2"><span class="s2">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s2">&gt;&gt;&gt; b = xrange(10000000)</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; sys.getsizeof(b)</span></div><div class="p2"><span class="s2">40</span></div><div class="p1"><span class="Apple-converted-space"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures; background-color: #ffffff} span.s2 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p2"><span class="s2">&gt;&gt;&gt; ## 40 bytes</span></div><div class="p2"><span class="s2"><br /></span></div><div class="p1">There is module called “six” which works both in python2 and python3</div><div class="p2"><span class="s2"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </span></div><div class="p1">Also tool called “2to3” to port python2 to python3. This is installed by default while installing python3</div><div class="p1"><br /></div><div class="p1"><span class="s1">nawlekha</span><span class="s2">@</span><span class="s3">NAWLEKHA-M-Q1GZ:</span><span class="s4"><b>~/Desktop/pyATS</b></span><span class="s2">$ 2to3 -w hello.py</span></div><div class="p2"><span class="s2"></span><br /></div><div class="p3"><span class="s1">nawlekha</span><span class="s5">@</span><span class="s2">NAWLEKHA-M-Q1GZ:</span><span class="s4"><b>~/Desktop/pyATS</b></span><span class="s5">$ cat hello.py</span></div><div class="p2"><span class="s2"></span><br /></div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #34bc26; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures; color: #33bbc8} span.s2 {font-variant-ligatures: no-common-ligatures} span.s3 {font-variant-ligatures: no-common-ligatures; color: #34bc26} span.s4 {font-variant-ligatures: no-common-ligatures; color: #afad24} span.s5 {font-variant-ligatures: no-common-ligatures; color: #000000} </style> </div><div class="p1"><span class="s2">## old program will backup with hello.py.bak</span></div><div class="p1"><span class="s2"><br /></span></div><div class="p1">dict can use () or {}<span class="Apple-converted-space">&nbsp;</span></div><div class="p1"><span class="Apple-converted-space"><br /></span></div><div class="p1"><span class="s1">another implementation of python is Jython. python implemented in Java</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p3">Iron Python : python on dot-net</div><div class="p4"><br /></div><div class="p3">Pyjs : Python incorporated in java script</div><div class="p4"><br /></div><div class="p3">Scipython is replacement of matlab, fortran</div><div class="p4"><br /></div><div class="p3">In python everything is object. even print() function is object.<span class="Apple-converted-space">&nbsp;</span></div><div class="p3">anything that u can name is object</div><div class="p4"><br /></div><div class="p1"><span class="Apple-converted-space"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p3">function are first class object in python</div><div class="p3"><br /></div><div class="p3"><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = 10</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; ## a has address of object or reference of object not value</span></div><div class="p1"><span class="s1">a is just label</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a)</span></div><div class="p1"><span class="s1">10</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = 'hello world'</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a)</span></div><div class="p1"><span class="s1">hello world</span></div><div class="p3"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p3"><br /></div><div class="p1">##to copy list<span class="Apple-converted-space">&nbsp; </span>in python 2 <span class="Apple-converted-space">&nbsp; </span>either slice or list</div><div class="p2"><span class="s1">&gt;&gt;&gt; a = [10, 20, 30]</span></div><div class="p2"><span class="s1">&gt;&gt;&gt; b = a[:]</span></div><div class="p2"><span class="s1">&gt;&gt;&gt; b</span></div><div class="p2"><span class="s1">[10, 20, 30]</span></div><div class="p3"><span class="s1"></span><br /></div><div class="p2"><span class="s1">slicing is used to create copy of new object</span></div><div class="p2"><span class="s1">&gt;&gt;&gt; a = [10,20,30]</span></div><div class="p2"><span class="s1">&gt;&gt;&gt; b = list(a)</span></div><div class="p3"><span class="s1"></span><br /></div><div class="p2"><span class="s1">In python3 we use copy</span></div><div class="p2"><span class="s1">&gt;&gt;&gt; b = a.copy()</span></div><div class="p2"><span class="s1">&gt;&gt;&gt; b</span></div><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p2"><span class="s1">[10, 20, 30]</span></div><div class="p2"><span class="s1"><br /></span></div><div class="p2"><span style="color: #33bbc8; font-variant-ligatures: no-common-ligatures;">object doesn’t have scope but variable have</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">we can have class inside function</span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">every name in python is variable</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">## keys are case-insensitive in dict</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">nawlekha</span><span class="s2">@</span><span class="s3">NAWLEKHA-M-Q1GZ:</span><span class="s4"><b>~/Desktop/pyATS</b></span><span class="s2">$ python3</span></div><div class="p2"><span class="s3">Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin</span></div><div class="p2"><span class="s3">Type "help", "copyright", "credits" or "license" for more information.</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; a = "hello world"</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; b = "hello world"</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; c = a</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; id(a)</span></div><div class="p2"><span class="s3">4330160368</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; id(b)</span></div><div class="p2"><span class="s3">4330160496</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; id(c)</span></div><div class="p2"><span class="s3">4330160368</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; a == b</span></div><div class="p2"><span class="s3">True</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; a == c</span></div><div class="p2"><span class="s3">True</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; a is b</span></div><div class="p2"><span class="s3">False</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; a is c</span></div><div class="p2"><span class="s3">True</span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt; import sys</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; sys.getrefcount(b)</span></div><div class="p2"><span class="s3">2</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; sys.getrefcount(b) - 1</span></div><div class="p2"><span class="s3">1</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; d = a</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; e =a</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; e = a</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; f = a</span></div><div class="p2"><span class="s3">&gt;&gt;&gt; sys.getrefcount(b) - 1</span></div><div class="p2"><span class="s3">1</span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt; sys.getrefcount(a) - 1</span></div><div class="p2"><span class="s3">5</span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt; sys.getrefcount(a) - 1</span></div><div class="p2"><span class="s3">5</span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt; del c</span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt; sys.getrefcount(a) - 1</span></div><div class="p2"><span class="s3">4</span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s3">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p3"><span class="s3"></span><br /></div><div class="p3"><span class="s3"></span><br /></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #34bc26; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures; color: #33bbc8} span.s2 {font-variant-ligatures: no-common-ligatures; color: #000000} span.s3 {font-variant-ligatures: no-common-ligatures} span.s4 {font-variant-ligatures: no-common-ligatures; color: #afad24} </style> </span></div><div class="p2"><span class="s3">overtime the it will not check object. if it is already there reference will point to same</span></div><div class="p2"><span class="s3"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; name = "Nawraj"<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; import __main__</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; __main__.__dict__['name']</span></div><div class="p2"><span style="color: #33bbc8; font-variant-ligatures: no-common-ligatures;">'Nawraj'</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">## string are immutable</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = "hello"</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a, id(a))</span></div><div class="p1"><span class="s1">hello 4330156584</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a += "world"</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a, id(a))</span></div><div class="p1"><span class="s1">helloworld 4330143152</span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1"><span class="Apple-converted-space"><br /></span></span></div><div class="p1"><span class="s1">## for mutable strings ..use byte array</span></div><div class="p1"><span class="s1"><span class="Apple-converted-space">&nbsp;</span>&gt;&gt;&gt; a = bytearray(b"hello")</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a,id(a))</span></div><div class="p1"><span class="s1">bytearray(b'hello') 4330156752</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a += b"world"</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a,id(a))</span></div><div class="p1"><span class="s1">bytearray(b'helloworld') 4330156752</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = "This is a test string"</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; b = "This is a test string"</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a == b ## based on values</span></div><div class="p1"><span class="s1">True</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(id(a), id(b))</span></div><div class="p1"><span class="s1">4330151416 4330151488</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(hash(a), hash(b))<span class="Apple-converted-space">&nbsp; </span>## hash is calculated based on values.</span></div><div class="p1"><span class="s1"><span class="Apple-converted-space"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></span></div><div class="p1"><span class="s1">1551792690137147714 1551792690137147714</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">in python3 strings is by default unicode data<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = "hello world"<span class="Apple-converted-space">&nbsp; </span>## this is unicode<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; type(a)</span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1"><class str=""></class></span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">## byte array is unhashable</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = bytearray(b"Hello world")</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = bytearray(b"Hello world")</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; hash(a)</span></div><div class="p1"><span class="s1">Traceback (most recent call last):</span></div><div class="p1"><span class="s1"><span class="Apple-converted-space">&nbsp; </span>File "<stdin>", line 1, in <module></module></stdin></span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">TypeError: unhashable type: 'bytearray'</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">## collections</span></div><div class="p1"><span class="s1">3 tpyes</span></div><div class="p1"><span class="s1">set &gt;&gt; unordered collection of unique hashable objects</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = {10, 20 ,30 ,5 , -1 , 44}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a</span></div><div class="p1"><span class="s1">{5, 10, 44, 20, -1, 30}</span></div><div class="p1"><span class="s1">## it does not support item indexing</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a[0])</span></div><div class="p1"><span class="s1">Traceback (most recent call last):</span></div><div class="p1"><span class="s1"><span class="Apple-converted-space">&nbsp; </span>File "<stdin>", line 1, in <module></module></stdin></span></div><div class="p1"><span class="s1">TypeError: 'set' object does not support indexing</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">## set is mutable. we can add or remove but can't insert. elements in set are hashable</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.add(40)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.add(50)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a)</span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">{5, 40, 10, 44, 50, 20, -1, 30}</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.remove(44)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.remove(-1)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a</span></div><div class="p1"><span class="s1">{5, 40, 10, 50, 20, 30}</span></div><div class="p1"><span class="s1">## used basically for comparision. it’s inefficient using list</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">complexitiy is O(1)</span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">## element search in set is very fast</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = {10,20,44, 55,25}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; b = {65,35,10,20,44}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a &amp; b) ## intersection</span></div><div class="p1"><span class="s1">{10, 44, 20}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a -b) ## set difference</span></div><div class="p1"><span class="s1">{25, 55}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a | b ) ## union</span></div><div class="p1"><span class="s1">{65, 35, 10, 44, 20, 55, 25}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a ^ b)<span class="Apple-converted-space">&nbsp; </span>## symmetric difference</span></div><div class="p1"><span class="s1">{65, 35, 55, 25}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; c = {10,20,44}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(c &lt; a) ## c is subset of a</span></div><div class="p1"><span class="s1">True</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a &gt; c) ## a is superset of c</span></div><div class="p1"><span class="s1">True</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">## set is not indexable but it is iterable</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">## convert list to set to list</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = [10,20,30,40,30,30]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = list(sorted(set(a)))</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a</span></div><div class="p1"><span class="s1">[10, 20, 30, 40]</span></div><div class="p1"><span class="s1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1"><span class="Apple-converted-space"><br /></span></span></div><div class="p1"><span class="s1">sequences<span class="Apple-converted-space">&nbsp; </span>&gt;&gt;&gt; str bytes, bytes array, list, tuple, collection.deque, array.array</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = [10,20,30,40,50]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; 20 in a</span></div><div class="p1"><span class="s1">True</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; c = {"name": "nawraj", "place": "bangalore"}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; "place" in c</span></div><div class="p1"><span class="s1">True</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">complexity is O(n)</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">## timeit function is used to capture time in python</span></div><div class="p1"><span class="s1">from timeit import timeit</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = {"name": "nawraj", "role": "Admin"}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; b = {"name": "lekhak", "place": "Bangalore"}</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(a.keys() - b.keys())</span></div><div class="p1"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </div><div class="p1"><span class="s1">{'role'}</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = [10,20,30,40,50]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.insert(1,35)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a</span></div><div class="p1"><span class="s1">[10, 35, 20, 30, 40, 50]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; ## if i want to insert it in such a way list will be in sorted order</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; from bisect import insort<span class="Apple-converted-space">&nbsp; </span>## takes the midpoint and comapre like binary tree</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = [10,20,30,40,50]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; insort (a, 35)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; insort (a, 17)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a</span></div><div class="p1"><span class="s1">[10, 17, 20, 30, 35, 40, 50]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1"> <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">we can do append and sort but it is inefficient</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = []</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.append(25)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.append(35)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.append(67)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.append(70)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a</span></div><div class="p1"><span class="s1">[25, 35, 67, 70]</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.pop()</span></div><div class="p1"><span class="s1">70</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a.pop()</span></div><div class="p1"><span class="s1">67</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; ## adding element in any order and removing in sorted order called priority queue</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1"> <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1"><span class="Apple-converted-space"><br /></span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; from heapq import heappush, heappop</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a = []</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; heappush(a, 35)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; heappush(a, 37)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; heappush(a, 40)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; heappush(a, 46)</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(heappop(a))</span></div><div class="p1"><span class="s1">35</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(heappop(a))</span></div><div class="p1"><span class="s1">37</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(heappop(a))</span></div><div class="p1"><span class="s1">40</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(heappop(a))</span></div><div class="p1"><span class="s1">46</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; a</span></div><div class="p1"><span class="s1"><span class="Apple-converted-space"> <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></span></div><div class="p1"><span class="s1">[]</span></div><div class="p1"><span class="s1"><br /></span></div><div class="p1"><span class="s1">mapping &gt;&gt;&gt;</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">## zip is parallel compare. for parallel iteration</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; staff = "john", "nawraj"</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; places = "bangalore", "delhi"</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p1"><span class="s1">&gt;&gt;&gt; for s,p in zip (staff, places): print(s,p)</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">john bangalore</span></div><div class="p1"><span class="s1"> <style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-variant-ligatures: no-common-ligatures} </style> </span></div><div class="p1"><span class="s1">nawraj delhi</span></div><div class="p1"><br /></div>The goal of __repr__ is to be unambiguous<br />The goal of __str__ is to be readable<br /><br />PEMDAS : Parenthesis Exponent Multiplication Division Addition Subtraction<br /><br /><b>###print</b><br />&gt;&gt;&gt; age = 30<br />&gt;&gt;&gt; name = nawraj<br />&gt;&gt;&gt; print("%s is %s years old" % (name, age))<br />nawraj is 30 years old<br />&gt;&gt;&gt; print('{0} is {1} years old'.format(name, age))<br />nawraj is 30 years old<br />&gt;&gt;&gt;<br /><br />If you are running file directory then file name is __main__<br />if you are running file by importing first file then it will print first file name<br /><br />Generator doesn’t hold entire result in memory.<br />Generator is better with performance<br /><br />format in custom way:<br />print("First: {foo}, Second: {bar}".format(bar=22.42,foo=41))<br /><br /># reuse single. used more than once<br />print("More: {0:6.2f} or {0:6.3f}".format(5.1234))<br /><br /># ignore multiple. Extra parameters ignored.<br />print("More: {1:6.2f} or {1:6.3f}".format(12.345, 5.1234))<br /><br /><b>Class name</b><br />1. private (_)<br />- begins with single underscore<br />def _copy(list):<br /><br />- means used in present module<br />not available elsewhere<br />module “import” ignored<br />internal use only<br /><br />2. Framework-reserved (_ _)<br />- Two or more<br />&nbsp; must start and end with _<br />def __init__<br /><br />pip = pip install packages<br />Pypi = python package index<br />PEP : Python enhancement proposal<br /><br /><b># class defines methods and data attributes of particular object</b><br /><b># The special __init__ method of class.Its job is to initialize or assign some values to its data attributes whenever we first create object.</b><br /><b># attributes are data we can assign values to and which can be used later.</b><br /><b># methods are used to perform operation on data attributes</b><br /><b># class attributes can be used outside class</b><br /><br />lass Employee:<br />&nbsp; def __init__(self):<br />&nbsp; &nbsp; self.firstname = 'nawraj'<br />&nbsp; &nbsp; self.lastname = 'Lekhak'<br /><br />def main():<br />&nbsp; print('This python programming is now starting')<br /><br />main()<br /><br />whenever you define main it should be on level of class not within class because it is not class method and considered as main function.<br /><br /><b>### create class attributes</b><br />class Person:<br />&nbsp; 'Base class of a person'<br /><br />&nbsp; # class attributes<br />&nbsp; first_name = 'Nawraj'<br />&nbsp; last_name = 'lekhak'<br />&nbsp; age = 30<br /><br />def main():<br /><br />&nbsp; #print the title of the program<br /><br />&nbsp; print("\t *************Welcome to Employee Database ***********")<br />&nbsp; print()<br /><br />&nbsp; # Print the class attributes values.<br />&nbsp; print("First name is:", Person.first_name)<br />&nbsp; print("Last name is:", Person.last_name)<br />&nbsp; print("Age:", Person.age)<br />&nbsp; print() ## to add additional line for seperation<br /><br /># Call the main method to start the program<br />main()<br /><br />##create object based on Employee class<br /><br />class Employee:<br />&nbsp; 'Base class of a Employee'<br /><br />&nbsp; # set default constructor<br />&nbsp; def __init__(self):<br />&nbsp; &nbsp; self.first_name&nbsp; = "Nawraj" # to reference data attributes<br />&nbsp; &nbsp; self.last_name = "Lekhak"<br />&nbsp; &nbsp; self.uid = '321'<br /><br />def main():<br />&nbsp; # create object based on Employee class<br />&nbsp; employee_01 = Employee()<br />&nbsp; employee_02 = Employee()<br />&nbsp; employee_03 = Employee()<br /><br />##Obtain object attributes<br />class Employee:<br />&nbsp; 'Base class for our Employee'<br /><br />&nbsp; # set default constructor<br />&nbsp; def __init__(self):<br />&nbsp; &nbsp; self.first_name&nbsp; = "Nawraj" # to reference data attributes<br />&nbsp; &nbsp; self.last_name = "Lekhak"<br />&nbsp; &nbsp; self.uid = '321'<br /><br />&nbsp; def get_first_name(self):<br />&nbsp; &nbsp; return self.first_name<br /><br />&nbsp; def get_last_name(self):<br />&nbsp; &nbsp; return self.last_name<br /><br />&nbsp; def get_uid(self):<br />&nbsp; &nbsp; return self.uid<br /><br />def main():<br />&nbsp; # create object based on Employee class<br />&nbsp; employee_01 = Employee()<br /><br />&nbsp; ## Access and print the first last_name<br />&nbsp; print('First name:', employee_01.get_first_name())<br />&nbsp; print('Last name:', employee_01.get_last_name())<br />&nbsp; print('Uid:', employee_01.get_uid())<br /><br /># call main method<br />main()<br /><br /><b>##Changing object attribute values</b><br /><br />class Employees:<br />&nbsp; 'Base class for our Employees'<br /><br />&nbsp; # set default constructor when new objects are created<br />&nbsp; def __init__(self):<br />&nbsp; &nbsp; self.first_name&nbsp; = "n/a" # to reference data attributes<br />&nbsp; &nbsp; self.last_name = "n/a"<br />&nbsp; &nbsp; self.uid = 'n/a'<br /><br />def main():<br />&nbsp; # create object based on Employees class<br />&nbsp; employee_01 = Employees()<br />&nbsp; print('First name:', employee_01.first_name)<br />&nbsp; print('Last name:', employee_01.last_name)<br />&nbsp; print('Uid:', employee_01.uid)<br />&nbsp; print()<br /><br />&nbsp; # Let's modify this object attribute values<br />&nbsp; employee_01.first_name = 'Nawraj'<br />&nbsp; employee_01.last_name = 'Lekhak'<br />&nbsp; employee_01.uid = '388921'<br /><br />&nbsp; # Print new assigned values<br />&nbsp; print("New Values:")<br />&nbsp; print('First name:', employee_01.first_name)<br />&nbsp; print('Last name:', employee_01.last_name)<br />&nbsp; print('Uid:', employee_01.uid)<br /><br /># start out program<br />main()<br /><br /><b>##Acessing object methods</b><br /><br />class Employees:<br />&nbsp; 'Base class for Employees'<br /><br />&nbsp; # set default constructor when new objects are created<br />&nbsp; def __init__(self):<br />&nbsp; &nbsp; self.first_name&nbsp; = "Nawraj"<br />&nbsp; &nbsp; self.last_name = "Lekhak"<br />&nbsp; &nbsp; self.uid = '102'<br /><br />&nbsp; ## Getter method<br />&nbsp; def get_first_name(self):<br />&nbsp; &nbsp; return self.first_name<br /><br />&nbsp; def get_last_name(self):<br />&nbsp; &nbsp; return self.last_name<br /><br />&nbsp; def get_uid(self):<br />&nbsp; &nbsp; return self.uid<br /><br />&nbsp; ## set method<br />&nbsp; def set_first_name(self, xfirstname):<br />&nbsp; &nbsp; self.first_name = xfirstname<br /><br />&nbsp; def set_last_name(self, xlastname):<br />&nbsp; &nbsp; self.last_name = xlastname<br /><br />&nbsp; def set_uid(self, xuid):<br />&nbsp; &nbsp; self.uid = xuid<br /><br />def main():<br />&nbsp; # create object based on Employees class<br />&nbsp; employee = Employees()<br /><br /><b>&nbsp; ## access getter methods</b><br />&nbsp; print('First name:', employee.get_first_name())<br />&nbsp; print('Last name:', employee.get_last_name())<br />&nbsp; print('Uid:', employee.get_uid())<br />&nbsp; print()<br /><br /><b>&nbsp; # Modify object attributes Values</b><br />&nbsp; employee.set_first_name('John')<br />&nbsp; employee.set_last_name('Williams')<br />&nbsp; employee.set_uid('111')<br /><br /><b>&nbsp; # access setter methods</b><br />&nbsp; print("New Values:")<br />&nbsp; print('First name:', employee.get_first_name())<br />&nbsp; print('Last name:', employee.get_last_name())<br />&nbsp; print('Uid:', employee.get_uid())<br /><br /># start out program<br />main()<br /><b><br /></b> <b>## Passing arguments to constructor</b><br /><br />class Employee:<br />&nbsp; 'Base class for Employees'<br /><br />&nbsp; def __init__(self, myFirstName, myLastName, myUID):<br />&nbsp; &nbsp; self.first_name&nbsp; = myFirstName<br />&nbsp; &nbsp; self.last_name = myLastName<br />&nbsp; &nbsp; self.user_id = myUID<br /><br />&nbsp; def show_employee_details(self):<br />&nbsp; &nbsp; print('First Name:', self.first_name)<br />&nbsp; &nbsp; print('Last name:', self.last_name)<br />&nbsp; &nbsp; print("user id:", self.user_id)<br /><br />def main():<br />&nbsp; # create new object<br />&nbsp; employee = Employee('Nawraj', 'Lekhak','741')<br />&nbsp; employee01 = Employee('Ram', 'Bhatt','101')<br /><br />&nbsp; # Display employee show_employee_details<br />&nbsp; employee.show_employee_details()<br />&nbsp; print()<br />&nbsp; employee01.show_employee_details()<br /><br /># start out program<br />main()<br /><b><br /></b> <b>## destructor. Also known as garbage collector.</b><br /><br />class MyClass:<br /><br />&nbsp; def __init__(self):<br />&nbsp; &nbsp; print("Create new object..")<br /><br />&nbsp; def __del__(self):<br />&nbsp; &nbsp; print("Destroying used object..")<br /><br />def main():<br />&nbsp; # create new object<br />&nbsp; object1 = MyClass()<br />&nbsp; object2 = MyClass()<br />&nbsp; object3 = MyClass()<br /><br />&nbsp; print("\n\n") ## create two new line<br /><br />&nbsp; del(object1)<br />&nbsp; del(object2)<br />&nbsp; del(object3)<br /><br /># start out program<br />main()<br /><br /><b>## Public access modifier</b><br /><br />class BankAccount:<br /><br />&nbsp; def __init__(self, my_initial_balance):<br />&nbsp; &nbsp; self.balance = my_initial_balance<br /><br />&nbsp; def get_balance(self):<br />&nbsp; &nbsp; return self.balance<br /><br />def main():<br />&nbsp; # Create new bank Account.<br />&nbsp; account = BankAccount(500)<br /><br />&nbsp; #Display the current balance.<br />&nbsp; print('Current balance is $', account.get_balance())<br /><br />&nbsp; ## Access object attribute value outside class<br />&nbsp; account.balance += 800<br /><br />&nbsp; print('New balance is : $', account.get_balance())<br /><br /># start out program<br />main()<br /><br /><b>## Private access modifier</b><br /><br />class BankAccount:<br /><br />&nbsp; def __init__(self, my_starting_balance):<br />&nbsp; &nbsp; ## __ to make data attribute private to use within class<br />&nbsp; &nbsp; self.__balance = my_starting_balance<br /><br />&nbsp; def get_balance(self):<br />&nbsp; &nbsp; return self.__balance<br /><br />&nbsp; def deposit(self, amount_to_deposit):<br />&nbsp; &nbsp; self.__balance += amount_to_deposit<br /><br />def main():<br />&nbsp; # Create new bank Account.<br />&nbsp; account = BankAccount(500)<br /><br />&nbsp; account.deposit(400)<br /><br />&nbsp; #Display the starting balance.<br />&nbsp; print('Starting balance is: $', account.get_balance())<br /><br />&nbsp; ## This will not be acessible<br />&nbsp; print('Starting balance is: $', account.balance())<br /><br />&nbsp; account.balance += 4000<br />&nbsp; print('Starting balance is: $', account.get_balance())<br /><br /># start out program<br />main()<br /><br /><b># python child classes</b><br />class BankAccount:# Parent class<br />&nbsp; def __init__(self, initial_balance):<br />&nbsp; &nbsp; self.__balance = initial_balance<br /><br />&nbsp; def get_balance(self):<br />&nbsp; &nbsp; return self.__balance<br /><br />&nbsp; def deposit(self,amount):<br />&nbsp; &nbsp; self.__balance += amount<br /><br />&nbsp; def withdraw(self, amount):<br />&nbsp; &nbsp; self.__balance -= amount<br /><br />class SavingsAccount(BankAccount): # child class from BankAccount<br />&nbsp; def __init__(self,initial_balance):<br />&nbsp; &nbsp; BankAccount.__init__(self,initial_balance)<br /><br />def main():<br />&nbsp; # create savings account object<br />&nbsp; savings_account = SavingsAccount(200)<br /><br />&nbsp; # Display current __balance<br />&nbsp; print('SAving account balance $', savings_account.get_balance())<br />&nbsp; savings_account.deposit(300)<br />&nbsp; print('New account balance $', savings_account.get_balance())<br /><br /># start program<br />main()<br /><br /># python child classes<br />class BankAccount:# Parent class<br />&nbsp; def __init__(self, initial_balance):<br />&nbsp; &nbsp; self.__balance = initial_balance<br /><br />&nbsp; def get_balance(self):<br />&nbsp; &nbsp; return self.__balance<br /><br />&nbsp; def deposit(self,amount):<br />&nbsp; &nbsp; self.__balance += amount<br /><br />&nbsp; def withdraw(self, amount):<br />&nbsp; &nbsp; self.__balance -= amount<br /><br />class CheckingAccount(BankAccount): # child class<br /><br />&nbsp; def __init__(self,initial_balance):<br />&nbsp; &nbsp; BankAccount.__init__(self,initial_balance)<br /><br />def main():<br />&nbsp; # create checking account object<br />&nbsp; checking_account = CheckingAccount(300)<br /><br />&nbsp; # Display current __balance<br />&nbsp; print('Initial account balance $', checking_account.get_balance())<br />&nbsp; checking_account.deposit(300)<br />&nbsp; print('New balance with deposit $', checking_account.get_balance())<br />&nbsp; checking_account.withdraw(200)<br />&nbsp; print('New balance after withdraw $', checking_account.get_balance())<br /><br /># start program<br />main()<br /><br /><b># Inheritance. Class inherit from another class</b><br />class BankAccount:# Parent class<br />&nbsp; def __init__(self, initial_balance):<br />&nbsp; &nbsp; self.__balance = initial_balance<br /><br />&nbsp; def get_balance(self):<br />&nbsp; &nbsp; return self.__balance<br /><br />&nbsp; def deposit(self,amount):<br />&nbsp; &nbsp; self.__balance += amount<br /><br />&nbsp; def withdraw(self, amount):<br />&nbsp; &nbsp; if amount &gt; self.__balance:<br />&nbsp; &nbsp; &nbsp; print("You do not have enough fund")<br />&nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; self.__balance -= amount<br /><br />def main():<br />&nbsp; # create checking account object<br />&nbsp; account = BankAccount(100)<br /><br />&nbsp; # Display current balance<br />&nbsp; print('Initial account balance $', account.get_balance())<br />&nbsp; account.deposit(300)<br />&nbsp; print('New balance with deposit $', account.get_balance())<br />&nbsp; account.withdraw(500)<br />&nbsp; print('New balance after withdraw $', account.get_balance())<br /><br /># start program<br />main()<br /><br /><b># Import.&nbsp;</b><br />import savings_account # name of file without extension<br />import checking_account<br /><br />def main():<br /><br />&nbsp; # create a saving and checking account<br /><br />&nbsp; mySavingsAccount = savings_account.SavingsAccount(100)<br />&nbsp; myCheckingAccount = checking_account.CheckingAccount(500)<br /><br />&nbsp; # Display initial balance for both account<br />&nbsp; print('SAving account balance $', mySavingsAccount.get_balance())<br />&nbsp; print('Checking account balance $', myCheckingAccount.get_balance())<br /><br /># start program<br />main()<br /><br /><b># Overriding parent method within child class with same name. Also called polymorphism.&nbsp;</b><br /><br />class BankAccount:<br /><br />&nbsp; def __init__(self,myBalance):<br />&nbsp; &nbsp; self.__balance = myBalance<br /><br />&nbsp; def get_balance(self):<br />&nbsp; &nbsp; print('Calling the get_balance method from "Parent" class')<br /><br />class CheckingAccount(BankAccount):<br />&nbsp; def __init__(self, myBalance):<br />&nbsp; &nbsp; BankAccount.__init__(self,myBalance)<br /><br />&nbsp; def get_balance(self):<br />&nbsp; &nbsp; BankAccount.get_balance(self)## this will call parent class method. commenting this will call child class method<br />&nbsp; &nbsp; print('Calling the get_balance method from "Child" class')<br /><br />def main():<br />&nbsp; account = CheckingAccount(50)<br />&nbsp; account.get_balance()<br /><br />main()<br /><br />f __name__ == ‘__main__’:<br />&nbsp; &nbsp; &nbsp; &nbsp;main()<br />holds true if you are running script directly instead of import some module/file<br /># original string is always unchanged in python<br />python doesn’t pass by value or pass by null , it’s pass<br /><br />python debugger :<br />python script.py -pdb<br />import pdb<br />pdb.set_trace()<br /><br />Some useful ones to remember are:<br />b: set a breakpoint<br />c: continue debugging until you hit a breakpoint<br />s: step through the code<br />n: to go to next line of code<br />l: list source code for the current file (default: 11 lines including the line being executed)<br />u: navigate up a stack frame<br />d: navigate down a stack frame<br />p: to print the value of an expression in the current context<br />“To return both the key and value in a tuple, you can use the items() function:”<br />“A decorator is a function that takes one function as input and returns another function<br /><br /><b>Functions as arguments”</b><br />“If you don’t say global within a function, Python uses the local namespace and the variable is local. It goes away after the function completes.<br />Python provides two functions to access the contents of your namespaces:<br />locals() returns a dictionary of the contents of the local namespace.<br />globals() returns a dictionary of the contents of the global namespace”<br /><br /><b>“Uses of _ and __ in Names</b><br />Names that begin and end with two underscores (__) are reserved for use within Python, so you should not use them with your own variables. This naming pattern was chosen because it seemed unlikely to be selected by application developers for their own variables.”<br />For instance, the name of a function is in the system variable function .__name__, and its documentation string is function .__doc__:”<br /><br /><b>“Packages"</b><br />We went from single lines of code, to multiline functions, to standalone programs, to multiple modules in the same directory. To allow Python applications to scale even more, you can organize modules into file hierarchies called packages.<br />Maybe we want different types of text forecasts: one for the next day and one for the next week. One way to structure this is to make a directory named sources, and create two modules within it: daily.py and weekly.py. Each has a function called forecast. The daily version returns a string, and the weekly version returns a list of seven strings.<br />Here’s the main program and the two modules. (The enumerate() function takes apart a list and feeds each item of the list to the for loop, adding a number to each item as a little bonus.)<br />from sources import daily, weekly”<br /><br />“You’ll need one more thing in the sources directory: a file named __init__.py. This can be empty, but Python needs it to treat the directory containing it as a package”<br /><br />“Let’s try again, this time including the special Python object initialization method __init__:<br />&gt;&gt;&gt; class Person():<br />...&nbsp; &nbsp; &nbsp;def __init__(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pass<br />This is what you’ll see in real Python class definitions. I admit that the __init__() and self look strange. __init__() is the special Python name for a method that initializes an individual object from its class definition. 1 The self argument specifies that it refers to the individual object itself.<br />When you define __init__() in a class definition, its first parameter should be self. Although self is not a reserved word in Python, it’s common usage. No one reading your code later (including you!) will need to guess what you meant if you use self.”<br /><br /><b>Inheritance:</b><br />Creating a new class from an existing class but with some additions or changes. It’s an excellent way to reuse code. When you use inheritance, the new class can automatically use all the code from the old class but without copying any of it.<br />You define only what you need to add or change in the new class, and this overrides the behaviour of the old class. The original class is called a parent, superclass, or base class; the ”“new class is called a child, subclass, or derived class. These terms are interchangeable in object-oriented programming.<br />So, let’s inherit something. We’ll define an empty class called Car. Next, define a subclass of Car called Yugo. You define a subclass by using the same class keyword but with the parent class name inside the parentheses (class Yugo(Car) below):<br />&gt;&gt;&gt; class Car():<br />...&nbsp; &nbsp; &nbsp;pass<br />...<br />&gt;&gt;&gt; class Yugo(Car):<br />...&nbsp; &nbsp; &nbsp;pass<br />...<br />Next, create an object from each class:<br />&gt;&gt;&gt; give_me_a_car = Car()<br />&gt;&gt;&gt; give_me_a_yugo = Yugo()”<br /><br />“Without doing anything special, Yugo inherited the exclaim() method from Car. In fact, Yugo says that it is a Car, which might lead to an identity crisis. Let’s see what we can do about that.”<br /><br />“Use super() when the child is doing something its own way but still needs something from the parent (as in real life).”<br /><br />“The names of these methods begin and end with double underscores (__). You’ve already seen one: __init__ initializes a newly created object from its class definition and any arguments that were passed in.”<br /><br />@decorator_function<br />def display():<br />print(‘display function ran’)<br />is same as<br />display = decorator_function(display)<br /><br />__name__ : Every module in Python has a special attribute called __name__. It is a built-in variable that returns the name of the module.<br /><br />__main__ : Like other programming languages, Python too has an execution entry point i.e. main. 'main' is the name of the scope in which top-level code executes. Basically you have two ways of using a Python module: Run it directly as a script, or import it. When a module is run as a script, its __name__ is set to __main__.<br />Thus,the value of __name__ attribute is set to __main__ when the module is run as main program. Otherwise the value of __name__ is set to contain the name of the module.<br />__file__ represents the file the code is executing from<br />os.path.dirname(__file__) gives you the directory the file is in<br />os.path.pardir stands for ".." which means one directory above the current one<br />os.path.join(os.path.dirname(__file__), os.path.pardir) joins the directory name and ".."<br />os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) resolves the above path and gives you an absolute path for the parent directory of the directory your file is in<br /><br /><b>With statement in Python</b><br />In Python you need to give access to a file by opening it. You can do it by using<br />the open() function. Open returns a file object, which has methods and attributes<br />for getting information about and manipulating the opened file.<br />With statement<br />With the "With" statement, you get better syntax and exceptions handling.<br />"The with statement simplifies exception handling by encapsulating common<br />preparation and cleanup tasks."<br />In addition, it will automatically close the file. The with statement provides<br />a way for ensuring that a clean-up is always used.<br /><br />Without the with statement, we would write something like this:<br />file = open("welcome.txt")<br /><br />data = file.read()<br /><br />print data<br /><br />file.close()&nbsp; # It's important to close the file when you're done with it<br /><b><br /></b> <b>With Statement Usage</b><br />Opening a file using with is as simple as: with open(filename) as file:<br />with open("welcome.txt") as file: # Use file to refer to the file object<br /><br />&nbsp; &nbsp;data = file.read()<br /><br />&nbsp; &nbsp;do something with data<br />Opens output.txt in write mode<br />with open('output.txt', 'w') as file:&nbsp; # Use file to refer to the file object<br /><br />&nbsp; &nbsp; file.write('Hi there!')<br /><br />Notice, that we didn't have to write "file.close()". That will automatically be<br />called.<br /><br />The @ symbol is used for class, function and method decorators.<br /><b><br /></b> <b>The most common Python decorators you'll run into are:</b><br />@property<br />@classmethod<br />@staticmethod<br /><br /><b>Static Methods:</b><br />Simple functions with no self argument.<br />Work on class attributes; not on instance attributes.<br />Can be called through both class and instance.<br />The built-in function staticmethod()is used to create them.<br /><br />Benefits of Static Methods:<br />It localizes the function name in the classscope<br />It moves the function code closer to where it is used<br />More convenient to import versus module-level functions since each method does not have to be specially imported<br />@staticmethod<br />def some_static_method(*args, **kwds):<br />&nbsp; &nbsp; pass<br /><br /><b>Class Methods:</b><br />Functions that have first argument as classname.<br />Can be called through both class and instance.<br />These are created with classmethod in-built function.<br />&nbsp;@classmethod<br />def some_class_method(cls, *args, **kwds):<br />&nbsp; &nbsp; pass<br /><br /><span style="background-color: white; font-family: &quot;verdana&quot;; font-size: 14px;">##from given array or list [1,3,4,5,0,2] write a function which returns 2nd largest element</span><br /><div class="p2"><span class="s2">&gt;&gt;&gt; def second_largest(given_list):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>largest = None</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>second_largest = None</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for current_number in given_list:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>if largest == None:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>largest = current_number</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>elif current_number &gt; largest:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>second_largest = largest</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>largest = current_number</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>elif second_largest == None:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>second_largest = current_number</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>elif current_number &gt; second_largest:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>second_largest = current_number</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>return second_largest</span></div><div class="p3"><span class="s2"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; print(second_largest([1,3,4,5,0,2]))</span></div><div class="p2"><span class="s2">4</span></div><div class="p2"><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; print(second_largest([-2,-1]))</span></div><div class="p2"><span class="s2">-2</span></div><div class="p2"><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; print(second_largest([2, 2, 1]))</span></div><div class="p2"><span class="s2">2</span></div><div class="p2"><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; print(second_largest([2]))</span></div><div class="p2"><span class="s2">None</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; print(second_largest([]))</span></div><div class="p2"><span class="s2">None</span></div><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 14.0px Verdana; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000; background-color: #ffffff} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000; background-color: #ffffff; min-height: 14.0px} span.s1 {font-kerning: none} span.s2 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p2"><span class="s2">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><br /><div class="p1"><span class="s1">#Write a function that takes two strings and returns True if they are reverses of each other</span></div><div class="p1"><span class="s1">&gt;&gt;&gt; def are_reverses(string_1, string_2):</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for i in range(len(string_1)):</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>i_2 = len(string_2) - i - 1</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>if string_1[i] != string_2[i_2]:</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>return False</span></div><div class="p1"><span class="s1">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>return True</span></div><div class="p1"><span class="s1">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(are_reverses("ABC", "CBA"))</span></div><div class="p1"><span class="s1">True</span></div><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span class="s1">&gt;&gt;&gt; print(are_reverses("CBA", "AAA"))</span></div><div class="p1"><span class="s1">False</span></div><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p1"><span class="s1">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><br /><div class="p1"><span class="s1">## compare two strings as numbers</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; def larger_than(a,b):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>if len(a) &gt; len(b):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>return True</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>elif len(a) &lt; len(b):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>return False</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for i in range(len(a)):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>if a[i] == b[i]:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>continue</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>elif a[i] &gt; b[i]:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>return True</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>else:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>return False</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>return False</span></div><div class="p2"><span class="s2">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p3"><span class="s1"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; print(larger_than('525','1111'))</span></div><div class="p2"><span class="s2">False</span></div><div class="p4"><span class="s2"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; print(larger_than('6525','1111'))</span></div><div class="p2"><span class="s2">True</span></div><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 14.0px Verdana; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000; background-color: #ffffff} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 14.0px Verdana; background-color: #ffffff; min-height: 17.0px} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #000000; background-color: #ffffff; min-height: 14.0px} span.s1 {font-kerning: none} span.s2 {font-variant-ligatures: no-common-ligatures} </style> <br /><div class="p4"><span class="s2"></span><br /></div><div class="p1"><span class="s1">## 2 dimensional arrays</span></div><div class="p1"><span class="s1">1. as a list of list</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; a = [[1,3,9,4], [5,0,8,-3]]</span></div><div class="p2"><span class="s2">or</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; a = [[1,3,9,4],</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>[5,0,8,-3]]</span></div><div class="p3"><span class="s2"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; a</span></div><div class="p2"><span class="s2">[[1, 3, 9, 4], [5, 0, 8, -3]]</span></div><div class="p3"><span class="s2"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; a[0]</span></div><div class="p2"><span class="s2">[1, 3, 9, 4]</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; a[1]</span></div><div class="p2"><span class="s2">[5, 0, 8, -3]</span></div><div class="p3"><span class="s2"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; a[0][1] = 100</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; a</span></div><div class="p2"><span class="s2">[[1, 100, 9, 4], [5, 0, 8, -3]]</span></div><div class="p2"><span class="s2">&gt;&gt;&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p3"><span class="s2"></span><br /></div><div class="p2"><span class="s2">Two ways to iterate over a 2D array</span></div><div class="p2"><span class="s2">1. First way</span></div><div class="p3"><span class="s2"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; for row in a:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for item in row:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>print(item)</span></div><div class="p2"><span class="s2">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s2">1</span></div><div class="p2"><span class="s2">100</span></div><div class="p2"><span class="s2">9</span></div><div class="p2"><span class="s2">4</span></div><div class="p2"><span class="s2">5</span></div><div class="p2"><span class="s2">0</span></div><div class="p2"><span class="s2">8</span></div><div class="p2"><span class="s2">-3</span></div><div class="p3"><span class="s2"></span><br /></div><div class="p1"><span class="s1">2.<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s2">&gt;&gt;&gt; for i in range(len(a)):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for j in range(len(a[i])):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>print(a[i][j])</span></div><div class="p2"><span class="s2">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s2">1</span></div><div class="p2"><span class="s2">100</span></div><div class="p2"><span class="s2">9</span></div><div class="p2"><span class="s2">4</span></div><div class="p2"><span class="s2">5</span></div><div class="p2"><span class="s2">0</span></div><div class="p2"><span class="s2">8</span></div><div class="p4"><span style="font-size: 11px; font-variant-ligatures: no-common-ligatures;">-3</span></div><div class="p2"><br /></div><div class="p1"><span class="s1">### you are given a 2D array with the same number of rows and columns. Write a function that adds up the diagonal elements and returns the sum</span></div><div class="p2"><span class="s1"></span><br /></div><div class="p3"><span class="s2">&gt;&gt;&gt; def diagonal_sum(given_2d):</span></div><div class="p3"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>total = 0</span></div><div class="p3"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for i in range(len(given_2d)):</span></div><div class="p3"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>total += given_2d[i][i]</span></div><div class="p3"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>return total</span></div><div class="p3"><span class="s2">...<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span class="s1"></span><br /></div><div class="p3"><span class="s2">&gt;&gt;&gt; diagonal_sum([[1,0],[0,1]])</span></div><div class="p3"><span class="s2">2</span></div><div class="p3"><span class="s2">&gt;&gt;&gt; diagonal_sum([[1,2,3],[4,5,6],[7,8,9]])</span></div><div class="p2"><span style="font-family: &quot;menlo&quot;; font-size: 11px;">15</span></div><div class="p2"><span style="font-family: &quot;menlo&quot;; font-size: 11px;"><br /></span></div><div class="p1"><span class="s1">### Can rooks attack each other in chess board</span></div><div class="p2"><span class="s2">&gt;&gt;&gt; def rooks_are_safe(chessboard):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>n = len(chessboard)</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for row_i in range(n):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>row_count = 0</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>for col_i in range(n):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>row_count += chessboard[row_i][col_i]</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>if row_count &gt; 1:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>return False</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>for col_i in range(n):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>col_count = 0</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>for row_i in range(n):</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>col_count += chessboard[row_i][col_i]</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>if col_count &gt; 1:</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>return False</span></div><div class="p2"><span class="s2">... <span class="Apple-converted-space">&nbsp; &nbsp; </span>return True</span></div><div class="p3"><span class="s1"></span><br /></div><div class="p3"><span class="s1"></span><br /></div><div class="p2"><span class="s2">&gt;&gt;&gt; rooks_are_safe([[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,0,0]])</span></div><div class="p2"><span class="s2">True</span></div><div class="p2"><span class="s2">rooks_are_safe([1])</span></div><div class="p2"><span class="s2">True</span></div><div class="p2"><span class="s2">rooks_are_safe([[1,0],[1,0]]) ## they can attack each other</span></div><div class="p2"><span class="s2">False</span></div><div class="p2"><span class="s2">rooks_are_safe([[0,0,0],</span></div><div class="p2"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[1,0,1],</span></div><div class="p2"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[0,0,0]])</span></div><div class="p1"><span class="s1">False</span></div><div class="p3"><span class="s2"><br /></span></div><div class="p3"><span class="s2"><br /></span></div><br /></div><style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; background-color: #ffffff; min-height: 17.0px} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-kerning: none} span.s2 {font-variant-ligatures: no-common-ligatures} </style><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; background-color: #ffffff} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px} span.s1 {font-kerning: none} span.s2 {font-variant-ligatures: no-common-ligatures} </style><br /><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff} span.s1 {font-variant-ligatures: no-common-ligatures} </style></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com0tag:blogger.com,1999:blog-6880492769470667099.post-50657591223593415612017-09-29T13:40:00.000+05:302018-02-04T19:38:17.375+05:30PYTHON PROGRAMMING LANGUAGE<div dir="ltr" style="text-align: left;" trbidi="on"><b>Debugging :&nbsp;</b><br />#In interactive mode<br />python3 -i script.py import pdb<br />pdb.pm()<br /># This will take you to code and will show the line of error<br /><b><br /></b> <b># Launch debugger inside code</b><br />import pdb; pdb.set_trace()<br /><br /><b>## Program Structure</b><br />Variable name in python should always start with either _ or letter<br /><br />Indentation should be consistent . It can be of 2 spaces or 3 spaces or 4 spaces<br />Usually program are indented by 4 spaces.<br /><br /><b>## Formatted printing</b><br />name = 'Cisco'<br />shares = 100<br />price = 32.86<br />print('%10s %10d %10.2f' % (name, shares, price))<br /><br /><b>## values right aligned&nbsp;</b><br />print('{:&gt;10s} {:&gt;10d} {:&gt;10.2f}'.format(name, shares, price))<br /><br /><b># values left aligned</b><br />print('{:<10s d="" f="" format="" name="" p="" price="" shares=""><br /><b># for header</b><br />print('{:&gt;10s} {:&gt;10s} {:&gt;10s}'.format('Company','Shares','Price'))<br /><br /><b># We can also redirect output to filter</b><br />out = open('schedule.txt', 'w') # open file for writing<br />## tell output to go to that file<br />print('{:<10s d="" f="" file="out)&lt;/p" format="" name="" price="" shares="">out.close() # close the file<br /><br /># Now if we run the program, output will be redirected to file schedule.txt<br /><br /><b>## Text processing and files</b><br /># deal with .csv file<br />f = open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r')<br />print(f)<br />data = f.read() # this will read whole content of file at once<br />print(data)<br />f.close()<br /><br />name,date,shares,price<br />AA,06/11/07,100,32.2<br />IBM,13/05/17,50,91.1<br />CAT,23/09/06,150,83.44<br />MSFT,01/02/06,200,51.23<br />GR,31/10/06,95,40.3<br />MSFT,09/07/06,50,65.2<br />IBM,17/05/07,100,70.04<br />or<br />f = open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r')<br />for line in f: # read data line by line<br />&nbsp; print(line)<br />f.close()<br /><br />AA,06/11/07,100,32.2<br />IBM,13/05/17,50,91.1<br />CAT,23/09/06,150,83.44<br />MSFT,01/02/06,200,51.23<br />GR,31/10/06,95,40.3<br />MSFT,09/07/06,50,65.2<br />IBM,17/05/07,100,70.04<br /><br /><b>## Other way of working with file using with statement</b><br />with open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r') as f:<br />&nbsp; data = f.read()<br />print(data)<br /><br />## this will automatically take care of closing file<br /><br />name,date,shares,price<br />AA,06/11/07,100,32.2<br />IBM,13/05/17,50,91.1<br />CAT,23/09/06,150,83.44<br />MSFT,01/02/06,200,51.23<br />GR,31/10/06,95,40.3<br />MSFT,09/07/06,50,65.2<br />IBM,17/05/07,100,70.04<br /><br /><b># Working on string&nbsp;</b><br />c = 'hello'<br />d = 'world'<br />print(c + d) ## concatenate string<br />'helloworld'<br /><br /><b># To remove white space at beginning or end of line</b><br />line = '\n"Cisco", "2017.08.07", 100,32.88\n'<br />print(line.strip())<br />print(line)<br />"Cisco", "2017.08.07", 100,32.88<br /><br /><b># Remember string modification doesn't change original string. We need to save the result to have effect</b>.<br />line = line.strip()<br />print(line)<br />"Cisco", "2017.08.07", 100,32.88<br />print(line.replace('"','-'))<br />-Cisco-, -2017.08.07-, 100,32.88<br />print(line)<br />"Cisco", "2017.08.07", 100,32.88<br /><br />parts = line.split(',') ## result is list<br />print(parts)<br />['"Cisco"', ' "2017.08.07"', ' 100', '32.88']<br />parts[0]<br />'"Cisco"'<br />parts[1]<br />' "2017.08.07"'<br />parts[2]<br />' 100'<br />parts[0] = parts[0].strip('"') # to strip double quote<br />'Cisco'<br />parts[2] = int(parts[2])<br />100<br />parts[3] = float(parts[3])<br />32.88<br />print(parts[2] * parts[3])<br />3288.0000000000005<br /><br /><b>## Reading file and doing some calculation</b><br />total = 0.0<br />with open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r') as f:<br />&nbsp; headers = next(f) # skip a single line input<br />&nbsp; for line in f:<br />&nbsp; &nbsp; line = line.strip() # strip whitespace<br />&nbsp; &nbsp; parts = line.split(',')<br />&nbsp; &nbsp; parts[0] = parts[0].strip('"')<br />&nbsp; &nbsp; parts[1] = parts[1].strip('"')<br />&nbsp; &nbsp; parts[2] = int(parts[2])<br />&nbsp; &nbsp; parts[3] = float(parts[3])<br />&nbsp; &nbsp; total += parts[2]*parts[3]<br />&nbsp; &nbsp; print(parts)<br />&nbsp; <br />print('Total cost:', total)<br /><br />['AA', '06/11/07', 100, 32.2]<br />['IBM', '13/05/17', 50, 91.1]<br />['CAT', '23/09/06', 150, 83.44]<br />['MSFT', '01/02/06', 200, 51.23]<br />['GR', '31/10/06', 95, 40.3]<br />['MSFT', '09/07/06', 50, 65.2]<br />['IBM', '17/05/07', 100, 70.04]<br />Total cost: 44629.5<br /><br /><b># if csv file have date in&nbsp; comma separated format like "June 11, 2017" then we will have an issue. To open such .csv file, we can use import csv module</b><br /><b><br /></b> <b># we can also import library module csv to read csv files</b><br />import csv # to read , separted value files<br />f = open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r')<br />rows = csv.reader(f)<br />for row in rows: # this will take care of splitting rows apart and eliminating quotes<br />&nbsp; print(row)<br /><br />['name', 'date', 'shares', 'price']<br />['AA', '06/11/07', '100', '32.2']<br />['IBM', '13/05/17', '50', '91.1']<br />['CAT', '23/09/06', '150', '83.44']<br />['MSFT', '01/02/06', '200', '51.23']<br />['GR', '31/10/06', '95', '40.3']<br />['MSFT', '09/07/06', '50', '65.2']<br />['IBM', '17/05/07', '100', '70.04']<br /><br /><b>## Defining and using Simple functions:</b><br />def add(x,y):<br />&nbsp; result = x + y<br />&nbsp; return result<br /><br />print(add(4,5))<br /><br />#print(x) #Everything that happens in function stays inside function. x and y are local to a function<br /><br />print(add(x=10, y=15))<br /><br />print(add(y=15, x=10))<br /><br />print(add(5, y=20))<br />&nbsp; &nbsp; &nbsp; <br /><b>## Moving a script into function</b><br />import csv<br />def portfolio_cost(filename):<br />&nbsp; '''<br />&nbsp; computes calculation<br />&nbsp; '''<br />&nbsp; total = 0.0<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for row in rows:<br />&nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; total += row[2]*row[3]<br />&nbsp; return total&nbsp; <br />&nbsp; <br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />print('Total cost:', total)<br /><br />Total cost: 44629.5<br /><br /><b>#glob module</b><br />import glob # to match filenames with specific patterns<br />files = glob.glob('/Users/nawlekha/Desktop/pyATS//portfolio*.csv')<br />print(files)<br />## this will print all files portfolio1, 2 and so on..<br />for filename in files:<br />&nbsp; print(filename, portfolio_cost(filename))<br /><br />['/Users/nawlekha/Desktop/pyATS/portfolio.csv', '/Users/nawlekha/Desktop/pyATS/portfolio1.csv']<br />/Users/nawlekha/Desktop/pyATS/portfolio.csv 44629.5<br />/Users/nawlekha/Desktop/pyATS/portfolio1.csv 44629.5<br /><br /><b>## Data and Exception Handling</b><br />import csv<br />def portfolio_cost(filename):<br />&nbsp; '''<br />&nbsp; computes calculation<br />&nbsp; '''<br />&nbsp; total = 0.0<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/missing.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for row in rows:<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; total += row[2]*row[3]<br />&nbsp; return total&nbsp; <br /><br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv')<br />print('Total cost:', total)<br /><br />Bad row: ['CAT', '23/09/06', '', '83.44']<br />Bad row: ['MSFT', '09/07/06', 'N/A', '65.2']<br />Total cost: 28853.5<br />or<br />&nbsp; except ValueError as err: # this will store exception in variable err<br />&nbsp; &nbsp; &nbsp; print('Reason:', err) ## this will print exact error<br />&nbsp; &nbsp; <br />Bad row: ['CAT', '23/09/06', '', '83.44']<br />Reason: invalid literal for int() with base 10: ''<br />Bad row: ['MSFT', '09/07/06', 'N/A', '65.2']<br />Reason: invalid literal for int() with base 10: 'N/A'<br />Total cost: 28853.5<br />or<br /><br /><b># we can also print exact row number where error is seen</b><br /><br />import csv<br />def portfolio_cost(filename):<br />&nbsp; '''<br />&nbsp; computes calculation<br />&nbsp; '''<br />&nbsp; total = 0.0<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/missing.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; rowno = 0<br />&nbsp; &nbsp; for row in rows:<br />&nbsp; &nbsp; &nbsp; rowno += 1<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError as err:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Reason:', err)<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; total += row[2]*row[3]<br />&nbsp; return total&nbsp; &nbsp; <br /><br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv')<br />print('Total cost:', total)<br /><br />Row: 3 Bad row: ['CAT', '23/09/06', '', '83.44']<br />Row: 3 Reason: invalid literal for int() with base 10: ''<br />Row: 6 Bad row: ['MSFT', '09/07/06', 'N/A', '65.2']<br />Row: 6 Reason: invalid literal for int() with base 10: 'N/A'<br />Total cost: 28853.5<br />or<br /><br /><b># we can also use enumerate which gives extra counter with loops. Using it, we don't have to initialize data and increment it&nbsp;</b><br /><br />import csv<br />def portfolio_cost(filename):<br />&nbsp; '''<br />&nbsp; computes calculation<br />&nbsp; '''<br />&nbsp; total = 0.0<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/missing.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for rowno, row in enumerate(rows, start=1): # start means start of count<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError as err:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Reason:', err)<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; total += row[2]*row[3]<br />&nbsp; return total&nbsp; &nbsp; &nbsp; <br /><br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv')<br />print('Total cost:', total)<br /><br />Row: 3 Bad row: ['CAT', '23/09/06', '', '83.44']<br />Row: 3 Reason: invalid literal for int() with base 10: ''<br />Row: 6 Bad row: ['MSFT', '09/07/06', 'N/A', '65.2']<br />Row: 6 Reason: invalid literal for int() with base 10: 'N/A'<br />Total cost: 28853.5&nbsp; <br />&nbsp; <br />## Function design considerations<br />import csv<br />def portfolio_cost(filename):<br />&nbsp; '''<br />&nbsp; computes calculation<br />&nbsp; '''<br />&nbsp; total = 0.0<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/missing.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for rowno, row in enumerate(rows, start=1): # start means start of count<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError as err:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Reason:', err)<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; total += row[2]*row[3]<br />&nbsp; return total&nbsp; &nbsp; &nbsp; &nbsp; <br /><br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv')<br />print('Total cost:', total)<br /><br />Row: 3 Bad row: ['CAT', '23/09/06', '', '83.44']<br />Row: 3 Reason: invalid literal for int() with base 10: ''<br />Row: 6 Bad row: ['MSFT', '09/07/06', 'N/A', '65.2']<br />Row: 6 Reason: invalid literal for int() with base 10: 'N/A'<br />Total cost: 28853.5<br /><br /><b>##, unfortunately, we don't know what type of error code will generate. One thing we can do is catch all errors as:</b><br />&nbsp; &nbsp; except Exception as err: ## catches all errors but this is not good practice<br />&nbsp; &nbsp; so its better to avoid using this<br />&nbsp; <br /># another concern<br /><br />import csv<br />def portfolio_cost(filename, errors = 'warn'):<br />&nbsp; '''<br />&nbsp; computes calculation<br />&nbsp; '''<br />&nbsp; total = 0.0<br /><br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/missing.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for rowno, row in enumerate(rows, start=1): # start means start of count<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError as err:<br />&nbsp; &nbsp; &nbsp; &nbsp; if errors == 'warn':<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Reason:', err)<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; total += row[2]*row[3]<br />&nbsp; return total<br /><br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv', 'silent') ## this will skip print statement<br />print('Total cost:', total)<br /><br />Total cost: 28853.5<br />or<br />total = portfolio_cost('Data/missing.csv', errors = 'silent') # for better readable<br /><br />other way to force user to call this way is by using * in def function<br />def portfolio_cost(filename, *,errors = 'warn'):<br /><b># while calling, now use has to use keyword style</b><br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv',&nbsp; errors ='silent')<br /><br /><b># what if there are multiple values for errors</b><br />import csv<br />def portfolio_cost(filename, *, errors = 'warn'):<br />&nbsp; '''<br />&nbsp; computes total shares*price for a CSV file with name,date, shares,price data<br />&nbsp; '''<br />&nbsp; if errors not in { 'warn', 'silent', 'raise' }:<br />&nbsp; &nbsp; &nbsp; raise ValueError("errors must be one of 'warn', 'silent', 'raise'")<br />&nbsp; total = 0.0<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/missing.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for rowno, row in enumerate(rows, start=1): # start means start of count<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError as err:<br />&nbsp; &nbsp; &nbsp; &nbsp; if errors == 'warn':<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Reason:', err)<br />&nbsp; &nbsp; &nbsp; &nbsp; elif errors == 'raise':<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise # reraise last Exception<br />&nbsp; &nbsp; &nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; total += row[2]*row[3]<br /><br />total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv',&nbsp; errors ='ignore')<br />print('Total cost:', total)<br />&nbsp; &nbsp; <br /><b># if we enter bad value it will print errors must be one of 'warn', 'silent', 'raise'&nbsp; &nbsp;&nbsp;</b><br />Traceback (most recent call last):<br />&nbsp; File "/Users/nawlekha/Desktop/pyATS/test.py", line 27, in <module></module><br />&nbsp; &nbsp; total = portfolio_cost('/Users/nawlekha/Desktop/pyATS/missing.csv',&nbsp; errors ='ignore')<br />&nbsp; File "/Users/nawlekha/Desktop/pyATS/test.py", line 7, in portfolio_cost<br />&nbsp; &nbsp; raise ValueError("errors must be one of 'warn', 'silent', 'raise'")<br />ValueError: errors must be one of 'warn', 'silent', 'raise'<br /><br /><b>###Data structure and manipulation</b><br /><br /><b>#Bulit in data types</b><br /><br /><b>#tuple</b><br />t = ('AA', '2017-08-07', 100, 32.2) # this is called packing of values<br />print(len(t))<br />4<br />t[0]<br />'AA'<br />t[1]<br />'2017-08-07'<br />t[2]*t[3]<br />3220.0000000000005<br /><br /><b># we can do unpacking of values as;</b><br />name, date , shares, price = t<br />print(name)<br />print(date)<br />print(shares)<br />print(price)<br /><br />AA<br />2017-08-07<br />100<br />32.2<br /><br /><b># tuple are also immutable. Once it is created we can't change them</b><br />t[2] = 50<br /><br />Traceback (most recent call last):<br />&nbsp; File "/Users/nawlekha/Desktop/pyATS/test.py", line 15, in <module></module><br />&nbsp; &nbsp; t[2] = 50<br />TypeError: 'tuple' object does not support item assignment<br /><br /><b># list</b><br />names = ['IBM', 'YAHoo', 'Cisco', 'CAT']<br /># we can change the list items<br />print(names)<br />names.append('IBM')<br />names.insert(1, 'FB')<br />print(names)<br />names[2] = 'HPE'<br />print(names)<br /># basically in list all items are of same type<br /><br />['IBM', 'YAHoo', 'Cisco', 'CAT']<br />['IBM', 'FB', 'YAHoo', 'Cisco', 'CAT', 'IBM']<br />['IBM', 'FB', 'HPE', 'Cisco', 'CAT', 'IBM']<br /><br /><b># set&nbsp;</b><br />distinct_names = {'YAHoo', 'IBM', 'IBM', 'Cisco', 'Yahoo', 'Cisco'}<br /># eliminates duplicate items<br />print(distinct_names)<br /><br />{'Yahoo', 'Cisco', 'YAHoo', 'IBM'}<br /><br /><b>#one use of set is we can convert list to set to eliminate dups&nbsp;</b><br />set(names)<br />{'CAT', 'IBM', 'Cisco', 'YAHoo'}<br /><br /><b>#another use is to test membership</b><br />print('IBM' in distinct_names)<br />print('AA' in distinct_names)<br /><br />True<br />False<br /><br /><b># Dictionary: mapping between key and values</b><br />prices = {<br />&nbsp; 'IBM': 91.2,<br />&nbsp; 'MSFT': 45.23,<br />&nbsp; 'Cisco': 36.5<br />}<br /><br />print(prices['IBM'])<br />91.2<br /># we can also re-assign new values<br />prices['IBM'] = 87.23<br />print(prices)<br />{'IBM': 87.23, 'MSFT': 45.23, 'Cisco': 36.5}<br /><br /><b># we can also test membership</b><br />print('IBM' in prices)<br />True<br /><br /><b># we can have list of tuples</b><br />items = [('AA', 100, 32.2), ('MSFT', 50, 91.2)]<br /><br />[('AA', 100, 32.2), ('MSFT', 50, 91.2)]<br /><b><br /></b> <b># for complicated Dictionary</b><br />prices = {<br />&nbsp; 'IBM' : {'current': 91.23, 'high': 94.23, 'low': 91.10}<br />}<br /><br />print(prices)<br />print(prices['IBM']['low'])<br /><br />{'IBM': {'current': 91.23, 'high': 94.23, 'low': 91.1}}<br />91.1<br /><b><br /></b> <b>## Building data structure from a file</b><br /><br /><b># one way to read data from data structure</b><br />import csv<br />def read_portfolio(filename, *,errors = 'warn'):<br />&nbsp; # read a CSV file with name, date, shares, price data into a list<br /><br />&nbsp; if errors not in {'warn', 'silent', 'raise'}:<br />&nbsp; &nbsp; &nbsp;raise ValueError("errors must be one of 'warn', 'silent', 'raise'")<br /><br />&nbsp; portfolio = [] # list of records<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for rowno, row in enumerate(rows, start=1): # start means start of count<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError as err:<br />&nbsp; &nbsp; &nbsp; &nbsp; if errors == 'warn':<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Reason:', err)<br />&nbsp; &nbsp; &nbsp; &nbsp; elif errors == 'raise':<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise # re-raise last Exception<br />&nbsp; &nbsp; &nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; record = tuple(row)<br />&nbsp; &nbsp; &nbsp; portfolio.append(record)<br />&nbsp; return portfolio<br />&nbsp; <br />portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />print(portfolio)<br />print(len(portfolio))<br />## this should return list of tuples. files is converted into rows<br />len(portfolio)<br /># each entry is row of tuples<br /><br />[('AA', '06/11/07', 100, 32.2), ('IBM', '13/05/17', 50, 91.1), ('CAT', '23/09/06', 150, 83.44), ('MSFT', '01/02/06', 200, 51.23), ('GR', '31/10/06', 95, 40.3), ('MSFT', '09/07/06', 50, 65.2), ('IBM', '17/05/07', 100, 70.04)]<br />7<br /><b><br /></b> <b># Still we can find the total</b><br />total = 0.0<br />for holding in portfolio:<br />&nbsp; total += holding[2]*holding[3] #shares* price<br /><br />print('Total cost:', total)<br /><br />Total cost: 44629.5<br /><br /><b>#or better way is&nbsp;</b><br />for name, date, shares, price in portfolio:<br />&nbsp; total += shares*price<br />print('Total cost:', total)<br /><br />Total cost: 44629.5<br /><br /><b># if file has many rows and columns then its better to use dictionary rather than tuple in code&nbsp;</b><br />import csv<br />def read_portfolio(filename, *,errors = 'warn'):<br />&nbsp; # read a CSV file with name, date, shares, price data into a list<br /><br />&nbsp; if errors not in {'warn', 'silent', 'raise'}:<br />&nbsp; &nbsp; &nbsp;raise ValueError("errors must be one of 'warn', 'silent', 'raise'")<br /><br />&nbsp; portfolio = [] # list of records<br />&nbsp; with open('/Users/nawlekha/Desktop/pyATS/portfolio.csv', 'r') as f:<br />&nbsp; &nbsp; rows = csv.reader(f)<br />&nbsp; &nbsp; headers = next(rows) # skip header rows<br />&nbsp; &nbsp; for rowno, row in enumerate(rows, start=1): # start means start of count<br />&nbsp; &nbsp; &nbsp; try:<br />&nbsp; &nbsp; &nbsp; &nbsp; row[2] = int(row[2])<br />&nbsp; &nbsp; &nbsp; &nbsp; row[3] = float(row[3])<br />&nbsp; &nbsp; &nbsp; except ValueError as err:<br />&nbsp; &nbsp; &nbsp; &nbsp; if errors == 'warn':<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Bad row:', row) # if find error skip to next row<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('Row:',rowno, 'Reason:', err)<br />&nbsp; &nbsp; &nbsp; &nbsp; elif errors == 'raise':<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise # re-raise last Exception<br />&nbsp; &nbsp; &nbsp; &nbsp; else:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass<br />&nbsp; &nbsp; &nbsp; &nbsp; continue<br />&nbsp; &nbsp; &nbsp; record = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'name': row[0],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'date': row[1],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'shares': row[2],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'price': row[3]<br />&nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; portfolio.append(record)<br />&nbsp; return portfolio # now it will return list of dictionary<br />&nbsp; <br />portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br /><br />total = 0.0<br />for holding in portfolio:<br />&nbsp; total += holding['shares']*holding['price']<br /><br />print('Total cost:', total)<br /><br />Total cost: 44629.5<br /><br /><b># Using dictionary we can re-use code in other programming language as well</b><br /># we can port&nbsp; code to java as<br />import jason<br />data = jason.dumps(portfolio)<br />print(data)<br /># if we want data back into python again<br />port = jason.loads(data)<br />print(port)<br /><br /><b># Data manipulation</b><br /># find all shares names from the list<br />names = []<br />for holding in portfolio:<br />&nbsp; names.append(holding['name'])<br />print(names)<br /><br />['AA', 'IBM', 'CAT', 'MSFT', 'GR', 'MSFT', 'IBM']<br /><br /><b># find all holding having share more than 100</b><br />more100 = []<br />for holding in portfolio:<br />&nbsp; if holding['shares'] &gt; 100:<br />&nbsp; &nbsp; more100.append(holding)&nbsp; <br />print(more100)<br /><br />[{'name': 'CAT', 'date': '23/09/06', 'shares': 150, 'price': 83.44}, {'name': 'MSFT', 'date': '01/02/06', 'shares': 200, 'price': 51.23}]<br /><br /><b># List comprehension</b><br />total = sum([holding['shares']*holding['price'] for holding in portfolio])<br /># here we are passing list of shares and price to sum<br />print(total)<br /><br />44629.5<br /><br />names = [holding['name'] for holding in portfolio]<br />print('Names:', names)<br />Names: ['AA', 'IBM', 'CAT', 'MSFT', 'GR', 'MSFT', 'IBM']<br /><br />more100 = [holding for holding in portfolio if holding['shares'] &gt; 100]<br />print('Shares:', more100)<br />Shares: [{'name': 'CAT', 'date': '23/09/06', 'shares': 150, 'price': 83.44}, {'name': 'MSFT', 'date': '01/02/06', 'shares': 200, 'price': 51.23}]<br /><br /><b># if we want only name of stock</b><br />more100 = [holding['name'] for holding in portfolio if holding['shares'] &gt; 100]<br />print('Stock:', more100)<br />Stock: ['CAT', 'MSFT']<br /><b><br /></b> <b># Now lets find share price comparison</b><br />names = [holding['name'] for holding in portfolio] # this has duplicate<br />print('Names:', names)<br /><br />#unique_names = set(names) or<br />unique_names = {holding['name'] for holding in portfolio}<br />print('Unique:', unique_names)<br />print(type(unique_names))<br /><br />namestr = ','.join(unique_names)<br />print('Namestr:', namestr)<br />print(type(namestr))<br /><br />Names: ['AA', 'IBM', 'CAT', 'MSFT', 'GR', 'MSFT', 'IBM']<br />Unique: {'CAT', 'IBM', 'GR', 'MSFT', 'AA'}<br /><class set=""></class><br />Namestr: CAT,IBM,GR,MSFT,AA<br /><class str=""></class><br /><br />import urllib.request<br />u = urllib.request.urlopen('http://finance.yahoo.com/d/quotes.csv?s={}&amp;f=l1'.format(namestr))<br />data = u.read()<br /># this will return prices of stocks<br />pricedata = data.split()<br />for name, price in zip(unique_names, pricedata): # to do pairing of stock name and price<br />&nbsp; print(name, '=', price)<br /><br /><b># to have same in dict format</b><br />prices = dict(zip(unique_names, pricedata))<br />prices['IBM']<br /><br /><b>## dictionary comprehension</b><br />prices = {name:float(price) for name, price in zip(unique_names, pricedata)}<br />print(prices)<br /><br />current_value = 0.0<br />for holding in portfolio:<br />&nbsp; current_value += holding['shares']* prices[holding['name']]<br />or<br />current_value = sum([holding['shares']* prices[holding['name']] for holding in portfolio])<br />change = current_value - total<br /><br /><b>## Sorting and Grouping</b><br />portfolio.sort()<br /># this will throw error becoz it doesn't know on what basis to sort<br />Traceback (most recent call last):<br />&nbsp; File "/Users/nawlekha/Desktop/pyATS/test.py", line 65, in <module></module><br />&nbsp; &nbsp; portfolio.sort()<br />TypeError: '&lt;' not supported between instances of 'dict' and 'dict'<br /><br />def holding_name(holding):<br />&nbsp; return holding['name']<br /><br />print(portfolio[0])<br /><br />portfolio.sort(key=holding_name)<br /><br />for holding in portfolio:<br />&nbsp; print(holding) # now return is dict with sorted names<br /><br />{'name': 'AA', 'date': '06/11/07', 'shares': 100, 'price': 32.2}<br />{'name': 'CAT', 'date': '23/09/06', 'shares': 150, 'price': 83.44}<br />{'name': 'GR', 'date': '31/10/06', 'shares': 95, 'price': 40.3}<br />{'name': 'IBM', 'date': '13/05/17', 'shares': 50, 'price': 91.1}<br />{'name': 'IBM', 'date': '17/05/07', 'shares': 100, 'price': 70.04}<br />{'name': 'MSFT', 'date': '01/02/06', 'shares': 200, 'price': 51.23}<br />{'name': 'MSFT', 'date': '09/07/06', 'shares': 50, 'price': 65.2}<br /><br /><b># Instead of defining function we can do sort based on lambda</b><br />portfolio.sort(key = lambda holding: holding['name'])<br /><br />a = lambda x: 10*x<br />a(10) # will return 100<br /><br /><b># for min and mix also, we can use lambda</b><br />print(min(portfolio, key = lambda holding: holding['price’]))<br />print(max(portfolio, key = lambda holding: holding['price’]))<br /><br />{'name': 'AA', 'date': '06/11/07', 'shares': 100, 'price': 32.2}<br />{'name': 'IBM', 'date': '13/05/17', 'shares': 50, 'price': 91.1}<br /><br /><b>## Group data</b><br />import itertools<br />for price, items in itertools.groupby(portfolio, key=lambda holding: holding['price']):<br />&nbsp; print('Price:', price)<br />&nbsp; for it in items:<br />&nbsp; &nbsp; print(' ', it)<br />&nbsp; <br />Price: 32.2<br />&nbsp; {'name': 'AA', 'date': '06/11/07', 'shares': 100, 'price': 32.2}<br />Price: 83.44<br />&nbsp; {'name': 'CAT', 'date': '23/09/06', 'shares': 150, 'price': 83.44}<br />Price: 40.3<br />&nbsp; {'name': 'GR', 'date': '31/10/06', 'shares': 95, 'price': 40.3}<br />Price: 91.1<br />&nbsp; {'name': 'IBM', 'date': '13/05/17', 'shares': 50, 'price': 91.1}<br />Price: 70.04<br />&nbsp; {'name': 'IBM', 'date': '17/05/07', 'shares': 100, 'price': 70.04}<br />Price: 51.23<br />&nbsp; {'name': 'MSFT', 'date': '01/02/06', 'shares': 200, 'price': 51.23}<br />Price: 65.2<br />&nbsp; {'name': 'MSFT', 'date': '09/07/06', 'shares': 50, 'price': 65.2}<br />&nbsp; <br /># lets take data and build dictionary on it<br />by_name = {name: list(items)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for name, items in itertools.groupby(portfolio, key=lambda holding: holding['holding_name'])<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />by_name['IBM']<br /><br />## Library functions and import<br />x = 42<br /><br />def spam():<br />&nbsp; &nbsp; print('x is', x)<br /><br />def run():<br />&nbsp; &nbsp; print('calling spam')<br />&nbsp; &nbsp; spam()<br /><br />print('Running')<br />run()<br /><br />Save this code in python file simple.py<br /><br /><b># Now we want to import this module simple</b><br />&gt;&gt;&gt; import simple # this will fetch the file and execute completely<br />Running<br />calling spam<br />x is 42<br /><br /><b>#Now every content of that module is accessible&nbsp;</b><br /><br />&gt;&gt;&gt; simple<br /><module esktop="" from="" nawlekha="" pyats="" sers="" simple.py="" simple=""></module><br />&gt;&gt;&gt; simple.x<br />42<br />&gt;&gt;&gt; simple.spam<br /><function 0x105603510="" at="" spam=""></function><br />&gt;&gt;&gt; simple.spam()<br />x is 42<br />&gt;&gt;&gt;<br /><b><br /></b> <b># we have inbuilt module as well</b><br />&gt;&gt;&gt; import math<br />&gt;&gt;&gt; math.cos(2)<br />-0.4161468365471424<br />&gt;&gt;&gt; math.sqrt(2)<br />1.4142135623730951<br />&gt;&gt;&gt;<br /><br />Another variation of import:<br /><br />&gt;&gt;&gt; from simple import run<br />In this case we will get same output but we will see only run() function. we will not have access to x and spam()<br />&gt;&gt;&gt; run()<br />calling spam<br />x is 42<br /><br />What this actually does is:<br />import simple<br />run = simple.run # copy<br />run()<br /><br />&gt;&gt;&gt; from simple import spam, x<br />&gt;&gt;&gt; spam()<br />x is 42<br />&gt;&gt;&gt; x<br />42<br />&gt;&gt;&gt;<br /><br /><b># if we want to change the value of x we need to import simple and change it</b><br />&gt;&gt;&gt; x = 13<br />&gt;&gt;&gt; x<br />13<br />&gt;&gt;&gt; spam()<br />x is 42<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; import simple<br />&gt;&gt;&gt; simple.x<br />42<br />&gt;&gt;&gt; simple.x = 37<br />&gt;&gt;&gt; spam()<br />x is 37<br /><br /><b>## another aspect of import is it is one time operation. First-time import will execute the code but not second time.</b><br />&gt;&gt; import simple<br />Running<br />calling spam<br />x is 42<br /><br />&gt;&gt;&gt; import simple ## no output. Python caches all of the modules already loaded and it will never reload again.<br />&gt;&gt;&gt;<br /><br /># to find path of module<br /><br />&gt;&gt;&gt; import sys<br />&gt;&gt;&gt; sys.modules['simple']<br /><module esktop="" from="" nawlekha="" pyats="" sers="" simple.py="" simple=""></module><br /><br />Note: if you change some code in module. You need to quit python or delete cache and import again to see the changes<br /><br />&gt;&gt;&gt; import sys<br />&gt;&gt;&gt; sys.path<br />['/Users/nawlekha/Desktop/pyATS', '/Library/Frameworks/Python.framework/Versions/3.6/bin', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']<br /><br /><b>Python will look for source code in these paths one by one. If it is not there it will throw error module not found</b><br /><br />If module is in different directory. we can update env : PYTHONPATH or append that dir as : sys.path.append(‘..’) and perform import<br /><br />x = 42<br /><br />def spam():<br />&nbsp; &nbsp; print('x is', x)<br /><br />def run():<br />&nbsp; &nbsp; print('calling spam')<br />&nbsp; &nbsp; spam()<br /><br /># it is not wise to expose these commented lines so will move under If statement<br />#print('Running')<br />#run()<br /><br /><b>#doing this python program will work as script</b><br />if __name__ == '__main__': # to check the name of the module and check if you are the main program or not<br />&nbsp; &nbsp; print('Running')<br />&nbsp; &nbsp; run()<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 simple.py<br />Running<br />calling spam<br />x is 42<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$<br /><br />Now if you import simple and run we won’t see that code<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import simple<br />&gt;&gt;&gt;<br /><br />Every single module knows its own name. There is global variable called __name__ defined in python and if you are the main program or you are in interactive shell your name is main<br /><br />&gt;&gt;&gt; import simple<br />&gt;&gt;&gt; __name__<br />'__main__'<br /><br />&gt;&gt;&gt; simple.__name__<br />'simple'<br /><br /><b>Note : code under if statement will execute if you are running it as main program.&nbsp;</b><br /><b>if you are using import statement, that code will not execute</b><br /><br />&gt;&gt;&gt; simple.spam()<br />x is 42<br /><br /><b>## Writing a General Purpsose CSV Parsing Module</b><br /><br />Instead of writing function to read .csv file we can do<br /><br />&gt;&gt;&gt; f = open("/Users/nawlekha/Desktop/pyATS/portfolio.csv", 'r')<br />&gt;&gt;&gt; import csv<br />&gt;&gt;&gt; rows = csv.reader(f)<br />&gt;&gt;&gt; headers = next(rows)<br />&gt;&gt;&gt; headers<br />['name', 'date', 'shares', 'price']<br />&gt;&gt;&gt; row = next(rows)<br />&gt;&gt;&gt; row<br />['AA', '06/11/07', '100', '32.2']<br />&gt;&gt;&gt; types = [str, str, int, float]<br />&gt;&gt;&gt; int('42')<br />42<br />&gt;&gt;&gt; float('4.2')<br />4.2<br />&gt;&gt;&gt; types<br />[<class str="">, <class str="">, <class int="">, <class float="">]</class></class></class></class><br />&gt;&gt;&gt; row<br />['AA', '06/11/07', '100', '32.2']<br />&gt;&gt;&gt; for func, val in zip(types, row):<br /><span style="white-space: pre;"> </span>print(func, val)<br /><span style="white-space: pre;"> </span><br /><class str=""> AA</class><br /><class str=""> 06/11/07</class><br /><class int=""> 100</class><br /><class float=""> 32.2</class><br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; converted = [func(val) for func, val in zip(types, row)]<br />&gt;&gt;&gt; converted<br />['AA', '06/11/07', 100, 32.2]<br />&gt;&gt;&gt; dict(zip(headers, converted))<br />{'name': 'AA', 'date': '06/11/07', 'shares': 100, 'price': 32.2}<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; import reader<br />&gt;&gt;&gt; portfolio = reader.read_csv('/Users/nawlekha/Desktop/pyATS/portfolio.csv', [str, str, int, float])<br />&gt;&gt;&gt; portfolio<br />[{'name': 'AA', 'date': '06/11/07', 'shares': 100, 'price': 32.2}, {'name': 'IBM', 'date': '13/05/17', 'shares': 50, 'price': 91.1}, {'name': 'CAT', 'date': '23/09/06', 'shares': 150, 'price': 83.44}, {'name': 'MSFT', 'date': '01/02/06', 'shares': 200, 'price': 51.23}, {'name': 'GR', 'date': '31/10/06', 'shares': 95, 'price': 40.3}, {'name': 'MSFT', 'date': '09/07/06', 'shares': 50, 'price': 65.2}, {'name': 'IBM', 'date': '17/05/07', 'shares': 100, 'price': 70.04}]<br />&gt;&gt;&gt;<br /><br />Now lets use this:<br />change our port.py file and use reader module<br /><br />import reader<br />def read_portfolio(filename, *, errors='warn'):<br />&nbsp; &nbsp; '''<br />&nbsp; &nbsp; read a csv file with name,date, shares, price data<br />&nbsp; &nbsp; '''<br />&nbsp; &nbsp; return reader.read_csv(filename, [str, str, int, float], errors=errors)<br />portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />total = 0.0<br />for holding in portfolio:<br />&nbsp; &nbsp; total += holding['shares']*holding['price']<br /><br />print('Total cost:', total)<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 port.py<br />Total cost: 44629.5<br /><br /># still we got output but using reader module<br /><br />If somebody want to run above code as main program then we will modify code as:<br /><br />import reader<br />def read_portfolio(filename, *, errors='warn'):<br />&nbsp; &nbsp; '''<br />&nbsp; &nbsp; read a csv file with name,date, shares, price data<br />&nbsp; &nbsp; '''<br />&nbsp; &nbsp; return reader.read_csv(filename, [str, str, int, float], errors=errors)<br /><br />if __name__ == ‘__main__’<br />&nbsp; &nbsp; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&nbsp; &nbsp; total = 0.0<br />&nbsp; &nbsp; for holding in portfolio:<br />&nbsp; &nbsp; &nbsp; &nbsp; total += holding['shares']*holding['price']<br /><br />&nbsp; &nbsp; print('Total cost:', total)<br /><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 port.py<br />Total cost: 44629.5<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$<br /><br /><b>## Making a package</b><br />How to create package ?<br />First create a directory and move some files to it. Create empty __init__.py file<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ mkdir portie<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ mv port.py reader.py portie<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ ls portie<br />port.py&nbsp; &nbsp; reader.py<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ touch portie/__init__.py<br /><br /><b># we&nbsp;are trying to isolate our program module with others programming module</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import portie.reader<br />&gt;&gt;&gt; port = portie.reader.read_csv('/Users/nawlekha/Desktop/pyATS/portfolio.csv', [str, str, int, float])<br />&gt;&gt;&gt; print(port)<br />[{'name': 'AA', 'date': '06/11/07', 'shares': 100, 'price': 32.2}, {'name': 'IBM', 'date': '13/05/17', 'shares': 50, 'price': 91.1}, {'name': 'CAT', 'date': '23/09/06', 'shares': 150, 'price': 83.44}, {'name': 'MSFT', 'date': '01/02/06', 'shares': 200, 'price': 51.23}, {'name': 'GR', 'date': '31/10/06', 'shares': 95, 'price': 40.3}, {'name': 'MSFT', 'date': '09/07/06', 'shares': 50, 'price': 65.2}, {'name': 'IBM', 'date': '17/05/07', 'shares': 100, 'price': 70.04}]<br />&gt;&gt;&gt;<br /><br /><b># some of the module might not work properly with package as shown below. This is because there might be other standard reader module somewhere.</b><br />&gt;&gt;&gt; import portie.port<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "/Users/nawlekha/Desktop/pyATS/portie/port.py", line 32, in <module></module><br />&nbsp; &nbsp; import reader<br />ModuleNotFoundError: No module named 'reader'<br />&gt;&gt;&gt;<br /><br /><b>One way to fix it is . Open port.py file and change “import reader” to “import portie.reader “.&nbsp;</b><br /><b>or&nbsp;</b><br /><b>change “import reader” to “from . import reader” # package relative import from same directory</b><br /><br />## use of __init__.py file<br />when we import any module, this file will get execute.<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS/portie$ vi __init__.py<br /><br />print('loading portie')<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import portie.port<br />loading portie<br />&gt;&gt;&gt;<br /><br /><b>## one use of this file is to perform initialization steps. Another use it to load symbols from sub-modules like.</b><br /><br />In init file:<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS/portie$ vi __init__.py<br /><br />print('loading portie')<br />from .port import read_portfolio<br />from .reader import read_csv<br /><br /><b># we can use those function without knowing what their sub-modules are</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import portie<br />loading portie<br />&gt;&gt;&gt; portie.read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />[{'name': 'AA', 'date': '06/11/07', 'shares': 100, 'price': 32.2}, {'name': 'IBM', 'date': '13/05/17', 'shares': 50, 'price': 91.1}, {'name': 'CAT', 'date': '23/09/06', 'shares': 150, 'price': 83.44}, {'name': 'MSFT', 'date': '01/02/06', 'shares': 200, 'price': 51.23}, {'name': 'GR', 'date': '31/10/06', 'shares': 95, 'price': 40.3}, {'name': 'MSFT', 'date': '09/07/06', 'shares': 50, 'price': 65.2}, {'name': 'IBM', 'date': '17/05/07', 'shares': 100, 'price': 70.04}]<br />&gt;&gt;&gt;<br /><br /><b>## Classes and Objects</b><br />to create object using class statement. Class is a convenient way to define data structure and to attach method to carry out operations on data.<br />instead of doing below calculation using dictionary, we can use class<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; holding = {'name': 'AA', 'date': '2007-06-11', 'shares': 100, 'price': 32}<br />&gt;&gt;&gt; holding[name]<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />NameError: name 'name' is not defined<br />&gt;&gt;&gt; holding['name']<br />'AA'<br />&gt;&gt;&gt; holding['shares']<br />100<br /><br />&gt;&gt;&gt; def cost(holding):<br />...&nbsp; &nbsp; &nbsp;return holding['shares']*holding['price']<br />...<br />&gt;&gt;&gt; cost(holding)<br />3200<br />&gt;&gt;&gt;<br /><br /><b>## Understanding attribute access</b><br />class Holding(object): # object is compulsory for python 2 and it is optional in python 3<br />&nbsp; def __init__(self, name, date, shares, price):<br />&nbsp; &nbsp; self.name = name<br />&nbsp; &nbsp; self.date = date<br />&nbsp; &nbsp; self.shares = shares<br />&nbsp; &nbsp; self.price = price<br />&nbsp; <br />&nbsp; def cost(self):<br />&nbsp; &nbsp; return self.shares*self.price<br />&nbsp; <br />&nbsp; def sell(self, nshares):<br />&nbsp; &nbsp; self.shares -= nshares<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; &gt;&gt;&gt; h = Holding('AA', '2017-08-17', 100, 35.5)<br /><br />three operations we can do with class<br />#get attributes<br />&gt;&gt;&gt; h.name<br />'AA'<br />&gt;&gt;&gt; h.price<br />35.5<br />&gt;&gt;&gt; h.shares<br />100<br /><br /># set attributes<br />h.shares = 50<br />print(h.shares)<br /><br /># delete attributes<br />del h.shares<br /><br /># we can also set new attributes like time but this can leads to some problem<br />h.time = '10 am'<br />print(h.time)<br /><br /># for get and set attributes alternatively we can used built in function<br />print(getattr(h, 'name')) # h.name<br />&gt;&gt;&gt; getattr(h, 'name')<br />'AA'<br /><br />setattr(h, 'shares', 50) # h.shares = 50<br />print(h.shares)<br /><br />delattr(h, 'shares')<br /><br /># call method<br />&gt;&gt;&gt; h.cost()<br />3550.0<br /><br />&gt;&gt;&gt; print('%10s %10d %10.2f' % (h.name, h.shares, h.cost()))<br />&nbsp; &nbsp; &nbsp; &nbsp; AA&nbsp; &nbsp; &nbsp; &nbsp; 100&nbsp; &nbsp; 3550.00<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; portfolio<br />[<__main__ .holding="" 0x1022964a8="" at="" object="">, <__main__ .holding="" 0x102296438="" at="" object="">, <__main__ .holding="" 0x102296518="" at="" object="">, <__main__ .holding="" 0x102296588="" at="" object="">, <__main__ .holding="" 0x1022965f8="" at="" object="">, <__main__ .holding="" 0x102296668="" at="" object="">, <__main__ .holding="" 0x1022966d8="" at="" object="">]</__main__></__main__></__main__></__main__></__main__></__main__></__main__><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; total = 0.0<br />&gt;&gt;&gt; for h in portfolio:<br />...&nbsp; &nbsp; &nbsp;total += h.shares * h.price<br />...<br />&gt;&gt;&gt; total<br />96525.0<br />&gt;&gt;&gt;<br /><b><br /></b> <b># we can do list comprehension as well</b><br /><br />&gt;&gt;&gt; names = [h.name for h in portfolio]<br />&gt;&gt;&gt; names<br />['AA', 'IBM', 'CAT', 'MSFT', 'GR', 'MSFT', 'IBM']<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; output_columns = ['name', 'shares', 'price']<br />&gt;&gt;&gt; for colname in output_columns:<br />...&nbsp; &nbsp; &nbsp;print(colname, '=', getattr(h, colname))<br />...<br />name = AA<br />shares = 100<br />price = 35.<br /><br />&gt;&gt;&gt; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; table.print_table(portfolio, ['names', 'shares'])<br />{:&gt;10s}.format(colname)<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "/Users/nawlekha/Desktop/pyATS/table.py", line 10, in print_table<br />&nbsp; &nbsp; print('{:&gt;10s}'.format(str(getattr(obj, colname))), end= '')<br />AttributeError: 'Holding' object has no attribute 'names'<br /><br />&gt;&gt;&gt; import importlib<br />&gt;&gt;&gt; importlib.reload(table)<br /><module esktop="" from="" nawlekha="" pyats="" sers="" table.py="" table=""></module><br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares'])<br /><br /><b>Class methods and Alternate Constructors:</b><br />=================================<br />One way to create object is by using classname . What if we want to create object in different way.<br />for that we are creating a file dateobj.py<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import dateobj<br />&gt;&gt;&gt; d = dateobj.Date(2012, 12, 21)<br />&gt;&gt;&gt; d.year<br />2012<br /><br />Let’s create object in diff way<br /><br />say we have<br /><br />s = ‘2007-06-11’<br />let’s make date from it, one way is<br /><br />&gt;&gt;&gt; s = '2007-06-11'<br />&gt;&gt;&gt; parts = s.split('-')<br />&gt;&gt;&gt; parts<br />['2007', '06', '11']<br />&gt;&gt;&gt; d = dateobj.Date(int(parts[0]), int(parts[1]), int(parts[2]))<br />&gt;&gt;&gt; d.year<br />2007<br /><br />We can also create a function that can return date from string<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import dateobj<br />&gt;&gt;&gt; d = dateobj.date_from_string('2007-06-11')<br />&gt;&gt;&gt; d<br /><dateobj .date="" 0x10232d3c8="" at="" object=""></dateobj><br />&gt;&gt;&gt; d.year<br />2007<br /><br />One issue of this is date_from_string function is kind of detached from class<br /><br />One way to solve this problem is using constructor @classmethod<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i dateobj.py<br />&gt;&gt;&gt; d = Date.from_string('2007-06-11')<br />&gt;&gt;&gt; d<br /><__main__ .date="" 0x102285cf8="" at="" object=""></__main__><br />or<br />&gt;&gt;&gt; e = Date(2012, 12 ,21)<br />&gt;&gt;&gt;<br /><br />this way we are using class to create a date. method is attached to class.<br /><br />let's create another constructor as well<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i dateobj.py<br />&gt;&gt;&gt; d = Date(2012, 12, 21)<br />&gt;&gt;&gt; e = Date.from_string('2007-06-11')<br />&gt;&gt;&gt; f = Date.today()<br />&gt;&gt;&gt; f.year<br />2017<br />&gt;&gt;&gt; f.month<br />8<br />&gt;&gt;&gt; f.day<br />14<br />&gt;&gt;&gt;<br /><br /><b>## Inheritance concepts (to use program extensively)</b><br /><br />class Parent(object):<br />&nbsp; def __init__(self, value):<br />&nbsp; &nbsp; self.value = value<br />&nbsp; <br />&nbsp; def spam(self):<br />&nbsp; &nbsp; print('Parent.spam', self.value)<br />&nbsp; <br />&nbsp; def grok(self):<br />&nbsp; &nbsp; print('Parent.grok')<br />&nbsp; &nbsp; self.spam()<br />&nbsp; <br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i inherit.py<br />&gt;&gt;&gt; p = Parent(42)<br />&gt;&gt;&gt; p.value<br />42<br />&gt;&gt;&gt; p.spam()<br />Parent.spam 42<br />&gt;&gt;&gt; p.gork<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />AttributeError: 'Parent' object has no attribute 'gork'<br />&gt;&gt;&gt; p.grok()<br />Parent.grok<br />Parent.spam 42<br />&gt;&gt;&gt;<br /><br />class Child1(Paren<b>t): # inherit attributes from Parent class</b><br />&nbsp; def yow(self): # we can add new method in Child class. Add something to original code. This is one benefit<br />&nbsp; &nbsp; print('Child1.yow')<br />&nbsp; <br />c = Child1(42)<br />print(c.value)<br /><br />print(c.spam())<br />print(c.grok())<br />print(c.yow())<br /><br />&gt;&gt;&gt; class Child1(Parent):<br />...&nbsp; &nbsp; &nbsp;def yow(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print('Child1.yow')<br />...<br />&gt;&gt;&gt; c = Child1(42)<br />&gt;&gt;&gt; c.value<br />42<br />&gt;&gt;&gt; c.spam()<br />Parent.spam 42<br />&gt;&gt;&gt; c.grok()<br />Parent.grok<br />Parent.spam 42<br />&gt;&gt;&gt; c.yow()<br />Child1.yow<br />&gt;&gt;&gt;<br /><br /><b>## Another benefit is we can redefine the existing classmethod</b><br />class Child2(Parent):<br />&nbsp; def spam(self):<br />&nbsp; &nbsp; print('Child2.spam', self.value)<br />&nbsp; <br />c2 = Child2(42)<br />print(c2.spam())<br /><br />print(c2.grok()) # now this will print Child2.spam 42 instead of Parent.spam 42<br /><br />&gt;&gt;&gt; class Child2(Parent):<br />...&nbsp; &nbsp; &nbsp;def spam(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print('Child2.spam', self.value)<br />...<br />&gt;&gt;&gt; c2 = Child2(42)<br />&gt;&gt;&gt; c2.spam()<br />Child2.spam 42<br />&gt;&gt;&gt; c2.grok()<br />Parent.grok<br />Child2.spam 42<br />&gt;&gt;&gt;<br /><br /><b>## We can also discard current/existing method and call original method</b><br />class Child3(Parent):<br />&nbsp; def spam(self):<br />&nbsp; &nbsp; print('Child3.spam')<br />&nbsp; &nbsp; super().spam() ## This invokes original spam() method<br /><br />c3 = Child3(42)<br />print(c3.spam())<br />## output is<br />#Child3.spam<br />#Parent.spam 42<br /><br />print(c3.grok())<br /><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class Child3(Parent):<br />...&nbsp; &nbsp; &nbsp;def spam(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print('Child3.spam')<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super().spam()<br />...<br />&gt;&gt;&gt; c3 = Child3(42)<br />&gt;&gt;&gt; c3.spam()<br />Child3.spam<br />Parent.spam 42<br />&gt;&gt;&gt; c3.grok()<br />Parent.grok<br />Child3.spam<br />Parent.spam 42<br />&gt;&gt;&gt;<br /><br /><b>## 4th benefit is we can add new attribute to object</b><br />class Child4(Parent):<br />&nbsp; def __init__(self, value, extra):<br />&nbsp; &nbsp; self.extra = extra<br />&nbsp; &nbsp; super().__init__(value)<br />&nbsp; <br />c4 = Child4(42, 37)<br />print(c4.value)<br /><br />print(c4.extra)<br /><br /><b>## Another benefit is we can have more than one Parent</b><br />class Parent2(object):<br />&nbsp; def yow(self):<br />&nbsp; &nbsp; print('Parent2.yow')<br />&nbsp; <br />class Child5(Parent, Parent2): # we can inherit from more than one Parent. Kind of multiple inheritances<br />&nbsp; pass<br /><br />c5 = Child5(42)<br />print(c5.grok())<br />print(c5.spam())<br />print(c5.yow())<br /><br />&gt;&gt;&gt; class Child4(Parent):<br />...&nbsp; &nbsp; &nbsp;def __init__(self, value, extra):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;self.extra = extra<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super().__init__(value)<br />...<br />&gt;&gt;&gt; c4 = Child4(42, 37)<br />&gt;&gt;&gt; c4.value<br />42<br />&gt;&gt;&gt; c4.extra<br />37<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class Parent2(object):<br />...&nbsp; &nbsp; &nbsp;def yow(self):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print('Parent2.yow')<br />...<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class Child5(Parent, Parent2):<br />...&nbsp; &nbsp; &nbsp;pass<br />...<br />&gt;&gt;&gt; c5 = Child5(42)<br />&gt;&gt;&gt; c5.grok()<br />Parent.grok<br />Parent.spam 42<br />&gt;&gt;&gt; c5.spam()<br />Parent.spam 42<br />&gt;&gt;&gt; c5.yow()<br />Parent2.yow<br />&gt;&gt;&gt;<br /><b><br /></b> <b>## Building a extensible library:</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; portfolio = read_portfolio("/Users/nawlekha/Desktop/pyATS/portfolio.csv")<br />&gt;&gt;&gt; portfolio<br />[<__main__ .holding="" 0x102296470="" at="" object="">, <__main__ .holding="" 0x102296400="" at="" object="">, <__main__ .holding="" 0x1022964e0="" at="" object="">, <__main__ .holding="" 0x102296550="" at="" object="">, <__main__ .holding="" 0x1022965c0="" at="" object="">, <__main__ .holding="" 0x102296630="" at="" object="">, <__main__ .holding="" 0x1022966a0="" at="" object="">]</__main__></__main__></__main__></__main__></__main__></__main__></__main__><br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'price'])<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />NameError: name 'table' is not defined<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'price'])<br />&nbsp; &nbsp; &nbsp; name&nbsp; &nbsp; &nbsp; price<br />&nbsp; &nbsp; &nbsp; &nbsp; AA&nbsp; &nbsp; &nbsp; 100.0<br />&nbsp; &nbsp; &nbsp; &nbsp;IBM&nbsp; &nbsp; &nbsp; &nbsp;50.0<br />&nbsp; &nbsp; &nbsp; &nbsp;CAT&nbsp; &nbsp; &nbsp; 150.0<br />&nbsp; &nbsp; &nbsp; MSFT&nbsp; &nbsp; &nbsp; 200.0<br />&nbsp; &nbsp; &nbsp; &nbsp; GR&nbsp; &nbsp; &nbsp; &nbsp;95.0<br />&nbsp; &nbsp; &nbsp; MSFT&nbsp; &nbsp; &nbsp; &nbsp;50.0<br />&nbsp; &nbsp; &nbsp; &nbsp;IBM&nbsp; &nbsp; &nbsp; 100.0<br />&gt;&gt;&gt;<br /><br />what if i want to have table in different format. say html table<br />'''<br />def print_table(objects, colnames):<br />&nbsp; &nbsp; '''<br />&nbsp; &nbsp; Make a nicely formatted table showing attributes from a list fo objects<br />&nbsp; &nbsp; '''<br />&nbsp; &nbsp; # Emit table headers<br />&nbsp; &nbsp; for colname in colnames:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('{:&gt;10s}'.format(colname), end=' ')<br />&nbsp; &nbsp; print()<br />&nbsp; &nbsp; for obj in objects:<br />&nbsp; &nbsp; &nbsp; &nbsp; # Emit a row of table data<br />&nbsp; &nbsp; &nbsp; &nbsp; for colname in colnames:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('{:&gt;10s}'.format(str(getattr(obj, colname))), end=' ')<br />&nbsp; &nbsp; &nbsp; &nbsp; print()<br />'''<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; portfolio = read_portfolio("/Users/nawlekha/Desktop/pyATS/portfolio.csv")<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; formatter = table.TextTableFormatter()<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares', 'price'], formatter)<br />&nbsp; &nbsp; &nbsp; name&nbsp; &nbsp; &nbsp;shares&nbsp; &nbsp; &nbsp; price<br />&nbsp; &nbsp; &nbsp; &nbsp; AA&nbsp; &nbsp; &nbsp; &nbsp; 100&nbsp; &nbsp; &nbsp; 100.0<br />&nbsp; &nbsp; &nbsp; &nbsp;IBM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;50&nbsp; &nbsp; &nbsp; &nbsp;50.0<br />&nbsp; &nbsp; &nbsp; &nbsp;CAT&nbsp; &nbsp; &nbsp; &nbsp; 150&nbsp; &nbsp; &nbsp; 150.0<br />&nbsp; &nbsp; &nbsp; MSFT&nbsp; &nbsp; &nbsp; &nbsp; 200&nbsp; &nbsp; &nbsp; 200.0<br />&nbsp; &nbsp; &nbsp; &nbsp; GR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;95&nbsp; &nbsp; &nbsp; &nbsp;95.0<br />&nbsp; &nbsp; &nbsp; MSFT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;50&nbsp; &nbsp; &nbsp; &nbsp;50.0<br />&nbsp; &nbsp; &nbsp; &nbsp;IBM&nbsp; &nbsp; &nbsp; &nbsp; 100&nbsp; &nbsp; &nbsp; 100.0<br />&gt;&gt;&gt;<br /><br /><b># to get comma separated values</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; portfolio = read_portfolio("/Users/nawlekha/Desktop/pyATS/portfolio.csv")<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; formatter = table.print_table(portfolio, ['name', 'shares'], formatter)<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />NameError: name 'formatter' is not defined<br />&gt;&gt;&gt; formatter = table.CSVTableFormatter()<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares'], formatter)<br />name,shares<br />AA,100<br />IBM,50<br />CAT,150<br />MSFT,200<br />GR,95<br />MSFT,50<br />IBM,100<br />&gt;&gt;&gt;<br /><br /><b># to print html table format</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; portfolio = read_portfolio("/Users/nawlekha/Desktop/pyATS/portfolio.csv")<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; formatter = table.HTMLTableFormatter()<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares'], formatter)<br /></10s></10s><br />name<br />shares<br /><br />AA<br />100<br /><br />IBM<br />50<br /><br />CAT<br />150<br /><br />MSFT<br />200<br /><br />GR<br />95<br /><br />MSFT<br />50<br /><br />IBM<br />100<br /><br />&gt;&gt;&gt;<br /><br /><b>#Advanced Inheritance:</b><br />Sometimes it will be tricky when we have more than one init function. will modify table.py to illustrate this<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; formatter = table.TextTableFormatter(width=25)<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares', 'price'], formatter)<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />NameError: name 'portfolio' is not defined<br />&gt;&gt;&gt; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; formatter = table.TextTableFormatter(width=25)<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares', 'price'], formatter)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shares&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;price<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AA&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;100&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;100.0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IBM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 50&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 50.0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CAT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;150&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;150.0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MSFT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;200&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;200.0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 95&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 95.0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MSFT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 50&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 50.0<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IBM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;100&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;100.0<br /><b><br /></b> <b>## we can take existing class and customise the way we want</b><br /><br />&gt;&gt;&gt; class QuotedTextTableFormatter(table.TextTableFormatter):<br />...&nbsp; &nbsp; &nbsp;def row(self, rowdata):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# Put quotes around all values<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;quoted = ['"{}"'.format(d) for d in rowdata]<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super().row(quoted)<br />...<br />&gt;&gt;&gt; formatter = QuotedTextTableFormatter()<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares', 'price'], formatter)<br />&nbsp; &nbsp; &nbsp; name&nbsp; &nbsp; &nbsp;shares&nbsp; &nbsp; &nbsp; price<br />&nbsp; &nbsp; &nbsp; "AA"&nbsp; &nbsp; &nbsp; "100"&nbsp; &nbsp; "100.0"<br />&nbsp; &nbsp; &nbsp;"IBM"&nbsp; &nbsp; &nbsp; &nbsp;"50"&nbsp; &nbsp; &nbsp;"50.0"<br />&nbsp; &nbsp; &nbsp;"CAT"&nbsp; &nbsp; &nbsp; "150"&nbsp; &nbsp; "150.0"<br />&nbsp; &nbsp; "MSFT"&nbsp; &nbsp; &nbsp; "200"&nbsp; &nbsp; "200.0"<br />&nbsp; &nbsp; &nbsp; "GR"&nbsp; &nbsp; &nbsp; &nbsp;"95"&nbsp; &nbsp; &nbsp;"95.0"<br />&nbsp; &nbsp; "MSFT"&nbsp; &nbsp; &nbsp; &nbsp;"50"&nbsp; &nbsp; &nbsp;"50.0"<br />&nbsp; &nbsp; &nbsp;"IBM"&nbsp; &nbsp; &nbsp; "100"&nbsp; &nbsp; "100.0"<br />&gt;&gt;&gt;<br /><br /><b>#Use of multiple inheritances. Customizing classes and overriding attributes</b><br /><br /># just inherit from object no relation to table formatter&nbsp; &nbsp; <br />class QuotedMixin(object):<br />&nbsp; &nbsp; def row(self, rowdata):<br />&nbsp; &nbsp; &nbsp; &nbsp; quoted = ['"{}"'.format(d) for d in rowdata]<br />&nbsp; &nbsp; &nbsp; &nbsp; super().row(quoted)<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; class Formatter(table.QuotedMixin, table.CSVTableFormatter):<br />...&nbsp; &nbsp; &nbsp;pass<br />...<br />&gt;&gt;&gt; formatter = Formatter()<br />&gt;&gt;&gt; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares', 'price'], formatter)<br />name,shares,price<br />"AA","100","100.0"<br />"IBM","50","50.0"<br />"CAT","150","150.0"<br />"MSFT","200","200.0"<br />"GR","95","95.0"<br />"MSFT","50","50.0"<br />"IBM","100","100.0"<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class Formatter(table.QuotedMixin, table.HTMLTableFormatter):<br />...&nbsp; &nbsp; &nbsp;pass<br />...<br />&gt;&gt;&gt; formatter = Formatter()<br />&gt;&gt;&gt; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; table.print_table(portfolio, ['name', 'shares', 'price'], formatter)<br />name<br />shares<br />price<br /><br />"AA"<br />"100"<br />"100.0"<br /><br />"IBM"<br />"50"<br />"50.0"<br /><br />"CAT"<br />"150"<br />"150.0"<br /><br />"MSFT"<br />"200"<br />"200.0"<br /><br />"GR"<br />"95"<br />"95.0"<br /><br />"MSFT"<br />"50"<br />"50.0"<br /><br />"IBM"<br />"100"<br />"100.0"<br /><br /><br /><b>##Designing of Inheritance:</b><br /><br />we can also put print_table function under TableFormatter class in table.py<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; import table<br />&gt;&gt;&gt; formatter = table.TextTableFormatter()<br />&gt;&gt;&gt; formatter.print_table(portfolio, ['name','shares'])<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />NameError: name 'portfolio' is not defined<br />&gt;&gt;&gt; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; formatter.print_table(portfolio, ['name','shares'])<br />&nbsp; &nbsp; &nbsp; name&nbsp; &nbsp; &nbsp;shares<br />&nbsp; &nbsp; &nbsp; &nbsp; AA&nbsp; &nbsp; &nbsp; &nbsp; 100<br />&nbsp; &nbsp; &nbsp; &nbsp;IBM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;50<br />&nbsp; &nbsp; &nbsp; &nbsp;CAT&nbsp; &nbsp; &nbsp; &nbsp; 150<br />&nbsp; &nbsp; &nbsp; MSFT&nbsp; &nbsp; &nbsp; &nbsp; 200<br />&nbsp; &nbsp; &nbsp; &nbsp; GR&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;95<br />&nbsp; &nbsp; &nbsp; MSFT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;50<br />&nbsp; &nbsp; &nbsp; &nbsp;IBM&nbsp; &nbsp; &nbsp; &nbsp; 100<br />&gt;&gt;&gt;<br /><br /><b>##Defensive programming with Abstract Base Class:</b><br /><br />from abc import ABC, abstractmethod<br /># abc is python standard module library<br /><br />we can recast TableFormatter so that it can inherit from ABC<br />class TableFormatter(ABC)<br /><br />then declare headings and row as abstract method<br /><br />&nbsp; &nbsp; @abstractmethod<br />&nbsp; &nbsp; def headings(self, headers):<br />&nbsp; &nbsp; &nbsp; &nbsp; pass<br /><br />&nbsp; &nbsp; @abstractmethod<br />&nbsp; &nbsp; def row(self, rowdata):<br />&nbsp; &nbsp; &nbsp; &nbsp; pass<br /><br />Instead of raising NotImplementedError this way we will get the exact error<br /><br />## we can also do type checking<br /><span style="white-space: pre;"> </span>if not isinstance(formatter, TableFormatter):<br /><span style="white-space: pre;"> </span>raise TypeError(‘formatter must be a TableFormatter’)<br />&nbsp; &nbsp; &nbsp; &nbsp; formatter.headings(colnames)<br />&nbsp; &nbsp; &nbsp; &nbsp; for obj in objects:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rowdata = [str(getattr(obj, colname)) for colname in colnames ]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; formatter.row(rowdata)<br /><br /># if somebody pass wrong class, this will catch that<br /><br /><b>## How inheritance actually works ?</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i inherit1.py<br />&gt;&gt;&gt; a = A()<br />&gt;&gt;&gt; a.spam()<br />A.spam<br />Parent.spam<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; exit()<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$<br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i inherit1.py<br />&gt;&gt;&gt; b = B()<br />&gt;&gt;&gt; b.spam()<br />B.spam<br />A.spam<br />Parent.spam<br />&gt;&gt;&gt;<br /><b><br /></b> <b># how this work is - every class keeps a record of its Parents using method resolution order (mro)</b><br /><br />&gt;&gt;&gt; B.__mro__<br />(<class main__.b="">, <class main__.a="">, <class main__.parent="">, <class object="">)</class></class></class></class><br />&gt;&gt;&gt;<br /><br /><b># this describes a chain of ancestors</b><br /><br />&gt;&gt;&gt; A.__mro__<br />(<class main__.a="">, <class main__.parent="">, <class object="">)</class></class></class><br />&gt;&gt;&gt;<br /><br /><b>## lets create C and D class and merge them</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i inherit1.py<br />&gt;&gt;&gt; a = A()<br />&gt;&gt;&gt; a.spam()<br />A.spam<br />Parent.spam<br />&gt;&gt;&gt; c = C()<br />&gt;&gt;&gt; c.spam()<br />C.spam<br />Parent.spam<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; d = D()<br />&gt;&gt;&gt; d.spam()<br />D.spam<br />Parent.spam<br /><br /># lets do multiple inheritance<br /><br />&gt;&gt;&gt; class E(A,C,D):<br />...&nbsp; &nbsp; &nbsp;pass<br />...<br />&gt;&gt;&gt; e = E()<br />&gt;&gt;&gt; e.spam()<br />A.spam<br />C.spam<br />D.spam<br />Parent.spam<br />&gt;&gt;&gt;<br /><br /># if we change the order, output will line in that order<br /><br />&gt;&gt;&gt; class F(D,C,A):<br />...&nbsp; &nbsp; &nbsp;pass<br />...<br />&gt;&gt;&gt; f = F()<br />&gt;&gt;&gt; f.spam()<br />D.spam<br />C.spam<br />A.spam<br />Parent.spam<br />&gt;&gt;&gt;<br /><br /><b>Two rules of inheritance</b><br />1. Any child class always needs to be checked before parent.<br />2. If you have more than one parents, then it should be checked in order.<br /><br />&gt;&gt;&gt; F.__mro__<br />(<class main__.f="">, <class main__.d="">, <class main__.c="">, <class main__.a="">, <class main__.parent="">, <class object="">)</class></class></class></class></class></class><br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; E.__mro__<br />(<class main__.e="">, <class main__.a="">, <class main__.c="">, <class main__.d="">, <class main__.parent="">, <class object="">)</class></class></class></class></class></class><br />&gt;&gt;&gt;<br /><br />use of super here is, it find itself in mro chain and moves one order above.<br />when we call C it will find itself in mro and moves one order above i.e. <class main__.a=""></class><br /><br /><b>## Python magic methods</b><br />&gt;&gt;&gt; x = 42<br />&gt;&gt;&gt; x + 10<br />52<br />&gt;&gt;&gt; x * 10<br />420<br /><br />same thing can be achieved as<br />&gt;&gt;&gt; x.__add__(10)<br />52<br />&gt;&gt;&gt; x.__mul__(10)<br />420<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; names = ['IBM', 'YAHOO', 'CISCO']<br />&gt;&gt;&gt; names[0]<br />'IBM'<br />or<br />&gt;&gt;&gt; names.__getitem__(0)<br />'IBM'<br />&gt;&gt;&gt; names[1] = 'FB'<br />or<br />&gt;&gt;&gt; names.__setitem__(1, 'FB')<br />&gt;&gt;&gt;<br /><br />## use of magic method to implement code<br />&gt;&gt;&gt; class Point(object):<br /><span style="white-space: pre;"> </span>def __init__(self, x, y):<br /><span style="white-space: pre;"> </span>self.x = x<br /><span style="white-space: pre;"> </span>self.y = y<br /><span style="white-space: pre;"> </span>def __add__(self, other):<br /><span style="white-space: pre;"> </span>print('Add', other)<br /><span style="white-space: pre;"> </span><br />&gt;&gt;&gt; p = Point(2,3)<br />&gt;&gt;&gt; p + 10<br />Add 10<br />&gt;&gt;&gt; p + 'hello'<br />Add hello<br />&gt;&gt;&gt; p + [1,2,3]<br />Add [1, 2, 3]<br />&gt;&gt;&gt; p + (4,5)<br />Add (4, 5)<br />&gt;&gt;&gt;<br /><b><br /></b> <b>## Making objects printable and debuggable</b><br /><br />for debugging purpose, we can use a “repr” method in class<br />in holding.py file<br />&nbsp; # used to control string output<br />&nbsp; def __repr__(self):<br />&nbsp; &nbsp; return 'Holding({!r}, {!r}, {!r}, {!r})'.format(self.name, self.date, self.shares, self.price)<br /><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-21', 100, 30.36)<br />&gt;&gt;&gt; h<br />Holding('AA', '2017-08-21', 100, 30.36)<br />&gt;&gt;&gt;<br /><br />This has nice output now.<br /><br />&gt;&gt;&gt; portfolio = read_portfolio('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; portfolio<br />[Holding('AA', '06/11/07', 100, 100.0), Holding('IBM', '13/05/17', 50, 50.0), Holding('CAT', '23/09/06', 150, 150.0), Holding('MSFT', '01/02/06', 200, 200.0), Holding('GR', '31/10/06', 95, 95.0), Holding('MSFT', '09/07/06', 50, 50.0), Holding('IBM', '17/05/07', 100, 100.0)]<br /><br /><b>This is very much descriptive now</b><br /><b><br /></b> <b>#we can change the string representation of object by using special method __repr__ under class</b><br /><b><br /></b> <b>There is another method __str__ which can be used for string conversion or print function</b><br /><br />&nbsp; def __str__(self):<br />&nbsp; &nbsp; return '{} share of {} at ${:0.2f}'.format(self.shares, self.name, self.price)<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-21', 100, 30.36)<br />&gt;&gt;&gt; print(h)<br />100 share of AA at $30.36<br /><br />## without print<br />&gt;&gt;&gt; h<br />Holding('AA', '2017-08-21', 100, 30.36)<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; str(h) ## string method output<br />'100 share of AA at $30.36'<br />&gt;&gt;&gt; repr(h) ## represents method output<br />"Holding('AA', '2017-08-21', 100, 30.36)"<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; from datetime import date<br />&gt;&gt;&gt; d = date(2012, 12, 21)<br />&gt;&gt;&gt; print(d)<br />2012-12-21<br />&gt;&gt;&gt; d<br />datetime.date(2012, 12, 21)<br />&gt;&gt;&gt; repr(d)<br />'datetime.date(2012, 12, 21)'<br />&gt;&gt;&gt; str(d)<br />'2012-12-21'<br />&gt;&gt;&gt;<br /><br /><b>## Making a custom container object</b><br /><br />python special method<br />for size we can have __len__ method<br />to get array indexing we can have __getitem__ method<br />for for loop, we can have __iter__<br /><br />def __len__(self):<br /><span style="white-space: pre;"> </span>return len(self.holdings)<br /><br />def __getitem__(self, n):<br /><span style="white-space: pre;"> </span>return self.holdings[n]<br /><br />def __iter__(self):<br /><span style="white-space: pre;"> </span>return self.holdings.__iter__()<br /><br />Every python operation is mapped to some method name<br /><br />using this if we execute holding.py we can do length, indexing and for loop on portfolio<br /><br />we can also do indexing by name by modifying __getitem__<br /><br />def __getitem__(self, n):<br /><span style="white-space: pre;"> </span>if isinstance(n, str):<br /><span style="white-space: pre;"> </span>return [h for h in self.holdings if h.name == n]<br /><span style="white-space: pre;"> </span>else:<br /><span style="white-space: pre;"> </span>return self.holdings[n]<br /><br />portfolio[‘IBM’]<br /><br /><b>## making a custom context manager</b><br /><b># normal way of using resource. use it and release it.</b><br /><br />&gt;&gt;&gt; import threading<br />&gt;&gt;&gt; lock = threading.Lock()<br />&gt;&gt;&gt; lock.acquire()<br />True<br />&gt;&gt;&gt; print("Use the lock")<br />Use the lock<br />&gt;&gt;&gt; lock.release()<br />&gt;&gt;&gt;<br /><br /><b>## This might be a problem since somebody might forgot to close file or release resource. One solution is use with statement</b><br /><br />&gt;&gt;&gt; with lock:<br /><span style="white-space: pre;"> </span>print("Use the lock")<br /><span style="white-space: pre;"> </span><br />Use the lock<br />&gt;&gt;&gt;<br /><br />Lets create a Manager class<br /><br />class Manager(object):<br />&nbsp; &nbsp; def __enter__(self):<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Entering')<br />&nbsp; &nbsp; &nbsp; &nbsp; return 'some value'<br /><br />&nbsp; &nbsp; def __exit__(self, ty, val, tb):<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Exiting')<br />&nbsp; &nbsp; &nbsp; &nbsp; print(ty, val, tb)<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import manager<br />&gt;&gt;&gt; m = manager.Manager()<br />&gt;&gt;&gt; m<br /><manager .manager="" 0x102185a58="" at="" object=""></manager><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; with m:<br />...&nbsp; &nbsp; &nbsp;print('Hello world')<br />...<br />Entering<br />Hello world<br />Exiting<br />None None None<br />&gt;&gt;&gt;<br /><br /><br />&gt;&gt;&gt; with m:<br />...&nbsp; &nbsp; &nbsp;print('hello world')<br />...&nbsp; &nbsp; &nbsp;for i in range(3):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print(i)<br />...<br />Entering<br />hello world<br />0<br />1<br />2<br />Exiting<br />None None None<br /><br /><b>##Here exit method is kind of used for cleanup purpose</b><br /><br />&gt;&gt;&gt; with m as val:<br />...&nbsp; &nbsp; &nbsp;print('val =', val)<br />...<br />Entering<br />val = some value<br />Exiting<br />None None Non<br /><br />&gt;&gt;&gt; with m:<br />...&nbsp; &nbsp; &nbsp;print('hello world')<br />...&nbsp; &nbsp; &nbsp;int('n/a') # some bad input<br />...<br />Entering<br />hello world<br />Exiting<br /><class alueerror=""> invalid literal for int() with base 10: 'n/a' <traceback 0x1021aab48="" at="" object=""></traceback></class><br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 3, in <module></module></stdin><br />ValueError: invalid literal for int() with base 10: 'n/a'<br /><br /><b>## Encapsulation (Owning the dot)<br />## Instance representation, attribute access and naming convention</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-22', 100, 32.2)<br />&gt;&gt;&gt; h<br />Holding('AA', '2017-08-22', 100, 32.2)<br />&gt;&gt;&gt; h.name<br />'AA'<br />&gt;&gt;&gt; h.shares<br />100<br />&gt;&gt;&gt; h.price<br />32.2<br />&gt;&gt;&gt;<br /><br />## Every instance we make is a layer on top of python dict<br /><br />&gt;&gt;&gt; h.__dict__<br />{'name': 'AA', 'date': '2017-08-22', 'shares': 100, 'price': 32.2}<br />&gt;&gt;&gt; h.__dict__['name']<br />'AA'<br />&gt;&gt;&gt; h.__dict__['yow'] = 42<br />&gt;&gt;&gt; h.yow<br />42<br />&gt;&gt;&gt;<br /><br /><b>## Every instance we make gets its own dictionary</b><br /><br />&gt;&gt;&gt; g = Holding('IBM', '2008-04-1', 50, 91.1)<br />&gt;&gt;&gt; g.__dict__<br />{'name': 'IBM', 'date': '2008-04-1', 'shares': 50, 'price': 91.1}<br />&gt;&gt;&gt;<br /><br />## “.” operation is actually working out of dictionary<br /><br />&gt;&gt;&gt; del h.yow<br />&gt;&gt;&gt; h.__dict__<br />{'name': 'AA', 'date': '2017-08-22', 'shares': 100, 'price': 32.2}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; h.cost()<br />3220.0000000000005<br />&gt;&gt;&gt; h.sell(25)<br />&gt;&gt;&gt; h.__dict__<br />{'name': 'AA', 'date': '2017-08-22', 'shares': 75, 'price': 32.2}<br />&gt;&gt;&gt;<br /><br /><b>## we don’t see cost and sell in dictionary because those functions are part of the class</b><br /><br />&gt;&gt;&gt; Holding<br /><class main__.holding=""></class><br />&gt;&gt;&gt; h.__class__<br /><class main__.holding=""></class><br />&gt;&gt;&gt; Holding.__dict__<br />mappingproxy({'__module__': '__main__', '__init__': <function 0x101a88510="" at="" holding.__init__="">, '__repr__': <function 0x101a88620="" at="" holding.__repr__="">, '__str__': <function 0x101a886a8="" at="" holding.__str__="">, 'cost': <function 0x101a88730="" at="" holding.cost="">, 'sell': <function 0x101a887b8="" at="" holding.sell="">, '__dict__': <attribute dict__="" objects="" of="" olding="">, '__weakref__': <attribute objects="" of="" olding="" weakref__="">, '__doc__': None})</attribute></attribute></function></function></function></function></function><br />&gt;&gt;&gt;<br /><br /><b>## Holding class has its own dictionary. Here we can see cost and sell method</b><br /><br />&gt;&gt;&gt; Holding.__dict__['cost']<br /><function 0x101a88730="" at="" holding.cost=""></function><br />&gt;&gt;&gt; Holding.__dict__['cost'](h)<br />2415.0<br />&gt;&gt;&gt;<br /><br />Naming conventions:<br />use of single and double __ on attributes<br /><br />&gt;&gt;&gt; class Spam(object):<br />...&nbsp; &nbsp; &nbsp;def __init__(self, value):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;self._value = value # "Private" or some internal implementation<br />...<br />&gt;&gt;&gt; s = Spam(42)<br />&gt;&gt;&gt; s._value<br />42<br />&gt;&gt;&gt; s._value = 45<br />&gt;&gt;&gt;<br /><br />we can access and change it but we should not do that<br /><br /><b>## Managed attributes with properties</b><br />use Holding class. lets not allow anyone to set some value to price<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&gt;&gt;&gt; h.sahres<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />AttributeError: 'Holding' object has no attribute 'sahres'<br />&gt;&gt;&gt; h.shares<br />100<br />&gt;&gt;&gt; h.price<br />32.2<br />&gt;&gt;&gt; h.price = 'a lot'<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; h.price = '38.4'<br />&gt;&gt;&gt; h.cost()<br />'38.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.4'<br />&gt;&gt;&gt; 100 * 38.4<br />3840.0<br />&gt;&gt;&gt; 100 * '38.4'<br />'38.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.438.4'<br />&gt;&gt;&gt;<br /><br />Let's lock this code and not allow anyone to do this change<br /><br />&nbsp; def get_price(self):<br />&nbsp; &nbsp; return self.price<br /><br />&nbsp; def set_price(self, newprice):<br />&nbsp; &nbsp; if not isinstance(newprice, float):<br />&nbsp; &nbsp; &nbsp; raise TypeError('Expected float')<br />&nbsp; &nbsp; self.price = newprice<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt;&nbsp; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&nbsp; File "<stdin>", line 1</stdin><br />&nbsp; &nbsp; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&nbsp; &nbsp; ^<br />IndentationError: unexpected indent<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&gt;&gt;&gt; h.get_price()<br />32.2<br />&gt;&gt;&gt; h.set_price('142.3')<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "holding.py", line 13, in set_price<br />&nbsp; &nbsp; raise TypeError('Expected float')<br />TypeError: Expected float<br />&gt;&gt;&gt; h.set_price(142.3)<br />&gt;&gt;&gt;<br /><br />One solution is hide the price using private attribute<br /><br />Either we have to do _price everywhere in file . To avoid that we can use price as property<br /><br />&nbsp; @property<br />&nbsp; def get_price(self):<br />&nbsp; &nbsp; return self._price<br /><br />&nbsp; @price.setter<br />&nbsp; def set_price(self, newprice):<br />&nbsp; &nbsp; if not isinstance(newprice, float):<br />&nbsp; &nbsp; &nbsp; raise TypeError('Expected float')<br />&nbsp; &nbsp; self._price = newprice<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&gt;&gt;&gt; h.price<br />32.2<br />&gt;&gt;&gt; h.shares<br />100<br />&gt;&gt;&gt; h.date<br />'2017-08-10'<br />&gt;&gt;&gt; h.name<br />'AA'<br />&gt;&gt;&gt; h.price = 45.23<br />&gt;&gt;&gt; h.price = '45.23'<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "holding.py", line 15, in price<br />&nbsp; &nbsp; raise TypeError('Expected float')<br />TypeError: Expected float<br />&gt;&gt;&gt;<br /><br /><b>##if we set wrong value it will generate a error. It’s a type checking<br />## With @property we can do different types of checking<br />## other thing is we can use it to avoid usage problems<br />## cost is a method. To call it we have to put parenthesis</b><br /><br />&gt;&gt;&gt; h.cost()<br />4523.0<br />&gt;&gt;&gt; h.cost<br /><bound 100="" 45.23="" holding.cost="" holding="" method="" of=""></bound><br />&gt;&gt;&gt;<br /><br />with the use of property we can call cost as h.cost<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&gt;&gt;&gt; h.cost<br />3220.0000000000005<br />&gt;&gt;&gt;<br /><br />Take attributes and hide them behind property. This gives us way of locking down internals of the object<br /><br /><b>## Managed attributes with Descriptors</b><br /><br />Typing property in every single code for type checking is tedious.<br />To tackle this problem, lets use __repr__ also we should know how “.” intercept property<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i holding.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&gt;&gt;&gt; h.__class__<br /><class main__.holding=""></class><br />&gt;&gt;&gt; h.__class__.__dict__['shares']<br /><property 0x1022be2c8="" at="" object=""></property><br />&gt;&gt;&gt; p = _<br />&gt;&gt;&gt; p<br /><property 0x1022be2c8="" at="" object=""></property><br />&gt;&gt;&gt; hasattr(p, '__get__')<br />True<br />&gt;&gt;&gt; p.__get__(h)<br />100<br />&gt;&gt;&gt; h.shares = 100<br />&gt;&gt;&gt; h.shares = '100'<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "holding.py", line 27, in shares<br />&nbsp; &nbsp; raise TypeError('Expected int')<br />TypeError: Expected int<br />&gt;&gt;&gt; p = h.__class__.__dict__['shares']<br />&gt;&gt;&gt; p<br /><property 0x1022be2c8="" at="" object=""></property><br />&gt;&gt;&gt;<br /><br /><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; hasattr(p, '__set__')<br />True<br />&gt;&gt;&gt; p.__set__(h, '100')<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "holding.py", line 27, in shares<br />&nbsp; &nbsp; raise TypeError('Expected int')<br />TypeError: Expected int<br />&gt;&gt;&gt;<br /><br /><b>## Descriptor is a object that implement “.” (Encapsulation)</b><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i validate.py<br />&gt;&gt;&gt; p = Point(2,3)<br />&gt;&gt;&gt; p.x<br />2<br />&gt;&gt;&gt; p.y<br />3<br />&gt;&gt;&gt; p.__dict__<br />{'x': 2, 'y': 3}<br />&gt;&gt;&gt; p.x = 45<br />&gt;&gt;&gt; p.y = 23<br />&gt;&gt;&gt; p.__dict__<br />{'x': 45, 'y': 23}<br />&gt;&gt;&gt; p.x = 'a lot' # set bad value<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "validate.py", line 11, in __set__<br />&nbsp; &nbsp; raise TypeError('Expected int')<br />TypeError: Expected int<br />&gt;&gt;&gt; p.x = 4.5<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "validate.py", line 11, in __set__<br />&nbsp; &nbsp; raise TypeError('Expected int')<br />TypeError: Expected int<br />&gt;&gt;&gt; p.z = 45<br />&gt;&gt;&gt; p.z = 'a lot' # this only cares about x and y<br />&gt;&gt;&gt;<br /><br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i validate.py<br />&gt;&gt;&gt;&nbsp; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&nbsp; File "<stdin>", line 1</stdin><br />&nbsp; &nbsp; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&nbsp; &nbsp; ^<br />IndentationError: unexpected indent<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&gt;&gt;&gt; h.shares<br />100<br />&gt;&gt;&gt; h.price = '32.2'<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "validate.py", line 25, in __set__<br />&nbsp; &nbsp; raise TypeError('Expected int')<br />TypeError: Expected int<br />&gt;&gt;&gt; h.shares = 'a lot'<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "validate.py", line 11, in __set__<br />&nbsp; &nbsp; raise TypeError('Expected int')<br />TypeError: Expected int<br />&gt;&gt;&gt;<br /><br /><b>## Object Wrappers and Proxies</b><br /><br />other way to take ownership of .<br />builtin attributes like getattribute<br /><br />&gt;&gt;&gt; h.__getattribute__<br /><method-wrapper 0x102285f28="" at="" getattribute__="" holding="" object="" of=""></method-wrapper><br />&gt;&gt;&gt; h.__getattribute__('name')<br />'AA'<br />&gt;&gt;&gt; h.__getattribute__('shares')<br />100<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; class Spam(object):<br />...&nbsp; &nbsp; &nbsp;def __getattribute__(self, name):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print('Getting:', name)<br />...<br />&gt;&gt;&gt; s = Spam()<br />&gt;&gt;&gt; s.x<br />Getting: x<br />&gt;&gt;&gt; s.spam<br />Getting: spam<br />&gt;&gt;&gt; s.foo<br />Getting: foo<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; h.shares = 100<br />or<br />&gt;&gt;&gt; h.__setattr__('shares', 100)<br /><br />&gt;&gt;&gt; class Readonly(object):<br />...&nbsp; &nbsp; &nbsp;def __init__(self, obj):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;self._obj = obj<br />...&nbsp; &nbsp; &nbsp;def __getattr__(self, name):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return getattr(self._obj, name)<br />...&nbsp; &nbsp; &nbsp;def __setattr__(self, name, value):<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if name == '_obj':<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super().__setattr__(name, value)<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else:<br />...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise AttributeError('Read only')<br />...<br />&gt;&gt;&gt; h<br /><__main__ .holding="" 0x102a85f98="" at="" object=""></__main__><br />&gt;&gt;&gt; p = Readonly(h)<br />&gt;&gt;&gt; p.name<br />'AA'<br />&gt;&gt;&gt; p.shares<br />100<br /><br />&gt;&gt;&gt; p.shares = 50<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "<stdin>", line 10, in __setattr__</stdin><br />AttributeError: Read only<br />&gt;&gt;&gt;<br /><br /><b>## Functions as objects:</b><br /><br />Whatever operation we can do on variable object same operations we can do on functions.<br /><br />&gt;&gt; x = 10<br />&gt;&gt;&gt; y = 'hello world'<br />&gt;&gt;&gt; items = [10,20]<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; def greeting(name):<br /><span style="white-space: pre;"> </span>print('Hello', name)<br /><br />&gt;&gt;&gt; greeting('nawraj')<br />Hello nawraj<br />&gt;&gt;&gt; greeting<br /><function 0x105602400="" at="" greeting=""></function><br />&gt;&gt;&gt; g = greeting<br />&gt;&gt;&gt; g('nawraj')<br />Hello nawraj<br />&gt;&gt;&gt; items<br />[10, 20]<br />&gt;&gt;&gt; items.append(greeting)<br />&gt;&gt;&gt; items<br />[10, 20, <function 0x105602400="" at="" greeting="">]</function><br />&gt;&gt;&gt; items[2]<br /><function 0x105602400="" at="" greeting=""></function><br />&gt;&gt;&gt; items[2]('nawraj')<br />Hello nawraj<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; import time<br />&gt;&gt;&gt; def after(seconds, func):<br /><span style="white-space: pre;"> </span>time.sleep(seconds)<br /><span style="white-space: pre;"> </span>func()<br /><br />&gt;&gt;&gt; def hello():<br /><span style="white-space: pre;"> </span>print('Hello World')<br /><br />&gt;&gt;&gt; after(5, hello) ## issue here is, there is no difference in calling variable and function<br />Hello World<br /><br />&gt;&gt;&gt; names = ['dave', 'Thomas', 'Lewis', 'paula']<br />&gt;&gt;&gt; names.sort(key=lambda name: name.upper())<br />&gt;&gt;&gt; names<br />['dave', 'Lewis', 'paula', 'Thomas']<br />&gt;&gt;&gt; a = lambda x: 10 * x<br />&gt;&gt;&gt; a(10)<br />100<br />&gt;&gt;&gt; greeting('nawraj')<br />Hello nawraj<br />&gt;&gt;&gt; after(5, greeting)<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; after(5, greeting)<br />&nbsp; File "<pyshell>", line 3, in after</pyshell><br />&nbsp; &nbsp; func()<br />TypeError: greeting() missing 1 required positional argument: 'name'<br /><br />&gt;&gt;&gt; ## we can solve it using lambda function<br />&gt;&gt;&gt; after(5, lambda: greeting('nawraj'))&nbsp; ## passing function as argument<br />Hello nawraj<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; def add(x,y):<br /><span style="white-space: pre;"> </span>def do_add():<br /><span style="white-space: pre;"> </span>print('Adding {} + {} -&gt; {}'.format(x,y,x+y))<br /><span style="white-space: pre;"> </span>return x+y<br /><span style="white-space: pre;"> </span>return do_add<br /><br />&gt;&gt;&gt; a = add(2,3)<br />&gt;&gt;&gt; a<br /><function add.="" locals="">.do_add at 0x105604950&gt;</function><br />&gt;&gt;&gt; a()<br />Adding 2 + 3 -&gt; 5<br />5<br />&gt;&gt;&gt; ## this is returing a function<br />&gt;&gt;&gt; b = add('hello', 'world')<br />&gt;&gt;&gt; b()<br />Adding hello + world -&gt; helloworld<br />'helloworld'<br />&gt;&gt;&gt; x<br />10<br />&gt;&gt;&gt; y<br />'hello world'<br /><br /><b>## Even after deleting x and y we are able to see the output. Actually add will get the variables and pass it to do_add</b><br /><br />&gt;&gt;&gt; del x<br />&gt;&gt;&gt; del y<br />&gt;&gt;&gt; x<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; x<br />NameError: name 'x' is not defined<br />&gt;&gt;&gt; y<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; y<br />NameError: name 'y' is not defined<br />&gt;&gt;&gt; a()<br />Adding 2 + 3 -&gt; 5<br />5<br />&gt;&gt;&gt; b()<br />Adding hello + world -&gt; helloworld<br />'helloworld'<br />&gt;&gt;&gt;<br /><br /><b>##&nbsp; Generating code with Closures</b><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3 -i typedproperty.py<br />&gt;&gt;&gt; h = Holding('AA', '2017-08-10', 100, 32.2)<br />&gt;&gt;&gt; h.shares<br />100<br />&gt;&gt;&gt; h.price<br />32.2<br />&gt;&gt;&gt; h.price = '32.2'<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "typedproperty.py", line 12, in prop<br />&nbsp; &nbsp; expected_type))<br />TypeError: Expected <class float=""></class><br />&gt;&gt;&gt; h.shares = '100'<br />Traceback (most recent call last):<br />&nbsp; File "<stdin>", line 1, in <module></module></stdin><br />&nbsp; File "typedproperty.py", line 12, in prop<br />&nbsp; &nbsp; expected_type))<br />TypeError: Expected <class int=""></class><br />&gt;&gt;&gt;<br /><br /><b>## Metaprogramming and Decorators</b><br />&gt;&gt;&gt; def func(x,y,z):<br /><span style="white-space: pre;"> </span>print(x,y,z)<br /><br />&gt;&gt;&gt; func(1,2,3)<br />1 2 3<br />&gt;&gt;&gt; func(1,z=2,y=3)<br />1 3 2<br />&gt;&gt;&gt; ## These are two ways of passing arguments to function<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; def func(x, *args):<br /><span style="white-space: pre;"> </span>print(x)<br /><span style="white-space: pre;"> </span>print(args)<br /><br />&gt;&gt;&gt; ## This will take any extra number of positional arguments<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## atleast one argument should be passed<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; func(1)<br />1<br />()<br />&gt;&gt;&gt; fun(1,2,3,4,5)<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; fun(1,2,3,4,5)<br />NameError: name 'fun' is not defined<br />&gt;&gt;&gt; func(1,2,3,4,5)<br />1<br />(2, 3, 4, 5)<br />&gt;&gt;&gt; ## all extra arguments goes to arg tuple<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; def func(x, **kwargs):<br /><span style="white-space: pre;"> </span>print(x)<br /><span style="white-space: pre;"> </span>print(kwargs)<br /><span style="white-space: pre;"> </span><br />&gt;&gt;&gt; ## This will take atleast one arguments and any other extra keyword arguments<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; func(1)<br />1<br />{}<br />&gt;&gt;&gt; func(1, xmin=10, xmax=20, color='red')<br />1<br />{'xmin': 10, 'xmax': 20, 'color': 'red'}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## we can also have fun having both args and kwargs. This will take any combination whatsoever<br />&gt;&gt;&gt; def func(*args, **kwargs):<br /><span style="white-space: pre;"> </span>print(args)<br /><span style="white-space: pre;"> </span>print(kwargs)<br /><br />&gt;&gt;&gt; func()<br />()<br />{}<br />&gt;&gt;&gt; func(1,2,3,4)<br />(1, 2, 3, 4)<br />{}<br />&gt;&gt;&gt; func(1,2,x=20,y=3)<br />(1, 2)<br />{'x': 20, 'y': 3}<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; argument goes to tuple and kwargs goes to dict<br />SyntaxError: invalid syntax<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## we can also call a function using tuple and dictionary<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; def func(a,b,c,d):<br /><span style="white-space: pre;"> </span>print(a,b,c,d)<br /><br />&gt;&gt;&gt; args = (1,2)<br />&gt;&gt;&gt; kwargs = {'c':3,'d':-1}<br />&gt;&gt;&gt; func(*args, **kwargs)<br />1 2 3 -1<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; data = (1,2,3,4)<br />&gt;&gt;&gt; func(*data)<br />1 2 3 4<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; def add(x,y):<br /><span style="white-space: pre;"> </span>return x+y<br /><br />&gt;&gt;&gt; def add_wrapper(*args, **kwargs):<br /><span style="white-space: pre;"> </span>print('Wrapping!')<br /><span style="white-space: pre;"> </span>return add(*args, **kwargs)<br /><br />&gt;&gt;&gt; add_wrapper(2,3)<br />Wrapping!<br />5<br />&gt;&gt;&gt; add_wrapper(y=3,x=2)<br />Wrapping!<br />5<br />&gt;&gt;&gt; add_wrapper(2, y=3)<br />Wrapping!<br />5<br /><br /><b>## Don’t repeat yourself - Introducing Decorators</b><br />Let’s have file sample.py with below code<br /><br />def add(x,y):<br />&nbsp; &nbsp; print('Calling add')<br />&nbsp; &nbsp; return x+y<br /><br />def sub(x,y):<br />&nbsp; &nbsp; print('Calling sub')<br />&nbsp; &nbsp; return x-y<br /><br />def mul(x,y):<br />&nbsp; &nbsp; print('Calling mul')<br />&nbsp; &nbsp; return x*y<br /><br />one irritating thing about this code is ..we have to add print for logging in every function<br /><br /><b>## Instead of this we can generalise the code. Create logcall.py</b><br /><br />def logged(func):<br />&nbsp; &nbsp; #Idea here is: Give me function, I'll put logging around it<br /><br />&nbsp; &nbsp; def wrapper(*args, **kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Calling', func.__name__)<br />&nbsp; &nbsp; &nbsp; &nbsp; return func(*args, **kwargs)<br /><br />&nbsp; &nbsp; return wrapper<br /><br />&gt;&gt;&gt; def add(x,y):<br /><span style="white-space: pre;"> </span>return x+y<br /><br />&gt;&gt;&gt; import logcall<br />&gt;&gt;&gt; add = logcall.logged(add)<br />&gt;&gt;&gt; add<br /><function locals="" logged.="">.wrapper at 0x100662e18&gt;</function><br />&gt;&gt;&gt; add(2,3)<br />Calling add<br />5<br />&gt;&gt;&gt; def sub(x,y)<br />SyntaxError: invalid syntax<br />&gt;&gt;&gt; def sub(x,y):<br /><span style="white-space: pre;"> </span>return x-y<br /><br />&gt;&gt;&gt; sub = logcall.logged(sub)<br />&gt;&gt;&gt; sub(4,5)<br />Calling sub<br />-1<br />&gt;&gt;&gt;<br /><br /><b>## by this way, we don’t have to change logging message in every function<br />## Now lets modify sample.py using decorators</b><br /><br />from logical import logged<br /><br />@logged<br />def add(x,y):<br />&nbsp; &nbsp; print('Calling add')<br />&nbsp; &nbsp; return x+y<br />or<br />def add(x,y):<br />&nbsp; &nbsp; print('Calling add')<br />&nbsp; &nbsp; return x+y<br />add = logged(add)<br /><div><br />@logged<br />def sub(x,y):<br />&nbsp; &nbsp; print('Calling sub')<br />&nbsp; &nbsp; return x-y<br /><br />@logged<br />def mul(x,y):<br />&nbsp; &nbsp; print('Calling mul')<br />&nbsp; &nbsp; return x*y<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import sample<br />Adding logging to add<br />Adding logging to sub<br />Adding logging to mul<br />&gt;&gt;&gt;<br /><br />&gt;&gt;&gt; sample.add(2,3)<br />Calling add<br />Calling add<br />5<br />&gt;&gt;&gt; sample.mul(4,5)<br />Calling mul<br />Calling mul<br />20<br />&gt;&gt;&gt; sample.sub(2,3)<br />Calling sub<br />Calling sub<br />-1<br />&gt;&gt;&gt;<br /><br />nawlekha@NAWLEKHA-M-Q1GZ:~/Desktop/pyATS$ python3<br />Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)<br />[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; import sample<br />Adding logging to add<br />Adding logging to sub<br />Adding logging to mul<br />&gt;&gt;&gt; sample.add<br /><function 0x102288ae8="" add="" at=""></function><br />&gt;&gt;&gt; sample.sub<br /><function 0x102288bf8="" at="" sub=""></function><br />&gt;&gt;&gt; help(sample.add)<br /><br /><b>## if we want to use decorator, we will use wrapper around a function<br /><br />## Class Decorators<br /><br />## Metaclasses</b><br />&gt;&gt;&gt; x = 42<br />&gt;&gt;&gt; y = 'hello'<br />&gt;&gt;&gt; z = 3.5<br />&gt;&gt;&gt; type(x)<br /><class int=""></class><br />&gt;&gt;&gt; type(y)<br /><class str=""></class><br />&gt;&gt;&gt; type(z)<br /><class float=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; x.__class__<br /><class int=""></class><br />&gt;&gt;&gt; y.__class__<br /><class str=""></class><br />&gt;&gt;&gt; z.__class__<br /><class float=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class Point(object):<br /><span style="white-space: pre;"> </span>def __init__(self, x, y):<br /><span style="white-space: pre;"> </span>self.x = x<br /><span style="white-space: pre;"> </span>self.y = y<br /><span style="white-space: pre;"> </span>def move(self, dx, dy):<br /><span style="white-space: pre;"> </span>self.x += dx<br /><span style="white-space: pre;"> </span>self.y += dy<br /><br />&gt;&gt;&gt; p = Point(2,3)<br />&gt;&gt;&gt; type(p)<br /><class main__.point=""></class><br />&gt;&gt;&gt; ## every object we make has type associated with it<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## same is with python inbuilt object as well<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; a = int()<br />&gt;&gt;&gt; a<br />0<br />&gt;&gt;&gt; b = float()<br />&gt;&gt;&gt; b<br />0.0<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; # every object in python is kind of class<br />&gt;&gt;&gt; Point<br /><class main__.point=""></class><br />&gt;&gt;&gt; int<br /><class int=""></class><br />&gt;&gt;&gt; float<br /><class float=""></class><br />&gt;&gt;&gt; str<br /><class str=""></class><br />&gt;&gt;&gt; x<br />42<br />&gt;&gt;&gt; type(x)<br /><class int=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; type(Point)<br /><class type=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; type(float)<br /><class type=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; type<br /><class type=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## type is a class which creates other class<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## let's see what all class has<br />&gt;&gt;&gt; name = 'Point'<br />&gt;&gt;&gt; bases = (object,) # 1-tuple<br /><br />&gt;&gt;&gt; def __init__(self, x, y):<br /><span style="white-space: pre;"> </span>self.x = x<br /><span style="white-space: pre;"> </span>self.y = y<br /><span style="white-space: pre;"> </span><br />&gt;&gt;&gt; def move(self, dx, dy):<br /><span style="white-space: pre;"> </span>self.x += dx<br /><span style="white-space: pre;"> </span>self.y += dy<br /><br />&gt;&gt;&gt; methods = {<br /><span style="white-space: pre;"> </span>'__init__': __init__,<br /><span style="white-space: pre;"> </span>'move': move<br /><span style="white-space: pre;"> </span>}<br />&gt;&gt;&gt; name<br />'Point'<br />&gt;&gt;&gt; bases<br />(<class object="">,)</class><br />&gt;&gt;&gt; methods<br />{'__init__': <function 0x1056069d8="" __init__="" at="">, 'move': <function 0x105606a60="" at="" move="">}</function></function><br />&gt;&gt;&gt; type<br /><class type=""></class><br />&gt;&gt;&gt;<br />&gt;&gt;&gt; Point = type(name, bases, methods)<br />&gt;&gt;&gt; Point<br /><class main__.point=""></class><br />&gt;&gt;&gt; p = Point(2,3)<br />&gt;&gt;&gt; p.x<br />2<br />&gt;&gt;&gt; p.x = 20<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## we can modify type class<br />&gt;&gt;&gt; class mytype(type):<br /><span style="white-space: pre;"> </span>def __new__(meta, clsname, bases, methods):<br /><span style="white-space: pre;"> </span>print('Creating:', clsname)<br /><span style="white-space: pre;"> </span>print('Bases:', bases)<br /><span style="white-space: pre;"> </span>print('Methods:', list(methods))<br /><span style="white-space: pre;"> </span>return super().__new__(meta, clsname, bases, methods)<br /><br />&gt;&gt;&gt; Point = mytype(name, bases, methods)<br />Creating: Point<br />Bases: (<class object="">,)</class><br />Methods: ['__init__', 'move']<br />&gt;&gt;&gt; p = Point(2,3)<br />&gt;&gt;&gt; p.x<br />2<br />&gt;&gt;&gt; p.y<br />3<br />&gt;&gt;&gt; p.move(2,3)<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class Point(metaclass=mytype):<br /><span style="white-space: pre;"> </span>def __init__(self, x, y):<br /><span style="white-space: pre;"> </span>self.x = x<br /><span style="white-space: pre;"> </span>self.y = y<br /><span style="white-space: pre;"> </span>def move(self, dx, dy):<br /><span style="white-space: pre;"> </span>self.x += dx<br /><span style="white-space: pre;"> </span>self.y += dy<br /><br />Creating: Point<br />Bases: ()<br />Methods: ['__module__', '__qualname__', '__init__', 'move']<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class NewPoint(Point):<br /><span style="white-space: pre;"> </span>def yow(self):<br /><span style="white-space: pre;"> </span>print('Yow')<br /><br />Creating: NewPoint<br />Bases: (<class main__.point="">,)</class><br />Methods: ['__module__', '__qualname__', 'yow']<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class MyPoint(NewPoint):<br /><span style="white-space: pre;"> </span>def spam(self):<br /><span style="white-space: pre;"> </span>pass<br /><br />Creating: MyPoint<br />Bases: (<class main__.newpoint="">,)</class><br />Methods: ['__module__', '__qualname__', 'spam']<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; class Base(metaclass=mytype):<br /><span style="white-space: pre;"> </span>pass<br /><br />Creating: Base<br />Bases: ()<br />Methods: ['__module__', '__qualname__']<br />&gt;&gt;&gt; class A(Base):<br /><span style="white-space: pre;"> </span>def yow(self):<br /><span style="white-space: pre;"> </span>pass<br /><br />Creating: A<br />Bases: (<class main__.base="">,)</class><br />Methods: ['__module__', '__qualname__', 'yow']<br /><br /><b>Iterators and Generators:</b><br />=====================<br />e.g. for<br /><br />&gt;&gt;&gt; names = ['Cisco', 'IBM', 'YAHOO']<br />&gt;&gt;&gt; for name in names:<br /><span style="white-space: pre;"> </span>print(name)<br /><span style="white-space: pre;"> </span><br />Cisco<br />IBM<br />YAHOO<br />&gt;&gt;&gt; ## there is a special method called __iter__() which does this<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; it = names.__iter__()<br />&gt;&gt;&gt; it<br /><list_iterator 0x1055f8cc0="" at="" object=""></list_iterator><br />&gt;&gt;&gt; ## this will return iterator object<br />&gt;&gt;&gt; ## then python will call repetadely next on it<br />&gt;&gt;&gt; it.__next__()<br />'Cisco'<br />&gt;&gt;&gt; it.__nect__()<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; it.__nect__()<br />AttributeError: 'list_iterator' object has no attribute '__nect__'<br />&gt;&gt;&gt; it.__next__()<br />'IBM'<br />&gt;&gt;&gt; it.__next__()<br />'YAHOO'<br />&gt;&gt;&gt; ## this happens till we get stopIteration<br />&gt;&gt;&gt; it.__next__()<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; it.__next__()<br />StopIteration<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; f = open('/Users/nawlekha/Desktop/pyATS/portfolio.csv','r')<br />&gt;&gt;&gt; it = f.__iter__()<br />&gt;&gt;&gt; it<br /><_io .textiowrapper="" encoding="UTF-8" mode="r" name="/Users/nawlekha/Desktop/pyATS/portfolio.csv"></_io><br />&gt;&gt;&gt; it.__next__()<br />'name,date,shares,price\n'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; it.__next__()<br />'AA,06/11/07,100,32.2\n'<br />&gt;&gt;&gt; it.__next__()<br />'IBM,13/05/17,50,91.1\n'<br />&gt;&gt;&gt; it.__next__()<br />'CAT,23/09/06,150,83.44\n'<br />&gt;&gt;&gt; it.__next__()<br />'MSFT,01/02/06,200,51.23\n'<br />&gt;&gt;&gt; it.__next__()<br />'GR,31/10/06,95,40.3\n'<br />&gt;&gt;&gt; it.__next__()<br />'MSFT,09/07/06,50,65.2\n'<br />&gt;&gt;&gt; it.__next__()<br />'IBM,17/05/07,100,70.04'<br />&gt;&gt;&gt; it.__next__()<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; it.__next__()<br />StopIteration<br />&gt;&gt;&gt;<br /><b><br />### customization of iterators</b><br /><br />&gt;&gt;&gt; ## we can do some greping with python<br />&gt;&gt;&gt; def grep(pattern, filename):<br /><span style="white-space: pre;"> </span>with open(filename) as f:<br /><span style="white-space: pre;"> </span>for line in f:<br /><span style="white-space: pre;"> </span>if pattern in line:<br /><span style="white-space: pre;"> </span>yield line<br /><br />&gt;&gt;&gt; for line in grep('IBM', '/Users/nawlekha/Desktop/pyATS/portfolio.csv'):<br /><span style="white-space: pre;"> </span>print(line)<br /><br />IBM,13/05/17,50,91.1<br /><br />IBM,17/05/07,100,70.04<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## Another way to define generators<br />&gt;&gt;&gt; nums = [1,2,3,4,5,6]<br />&gt;&gt;&gt; squares = [x*x for x in nums]<br />&gt;&gt;&gt; squares<br />[1, 4, 9, 16, 25, 36]<br />&gt;&gt;&gt; squares = (x*x for x in nums)<br />&gt;&gt;&gt; squares<br /><generator genexpr="" object=""> at 0x1055ff468&gt;</generator><br />&gt;&gt;&gt; for x in squares:<br /><span style="white-space: pre;"> </span>print(x)<br /><br /><br />1<br />4<br />9<br />16<br />25<br />36<br />&gt;&gt;&gt; sum(x*x for x in nums)<br />91<br />&gt;&gt;&gt; f = open('/Users/nawlekha/Desktop/pyATS/portfolio.csv')<br />&gt;&gt;&gt; ibm = (line for line in f if 'IBM' in line)<br />&gt;&gt;&gt; for line in ibm:<br /><span style="white-space: pre;"> </span>print(line)<br /><br />IBM,13/05/17,50,91.1<br /><br />IBM,17/05/07,100,70.04<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; ## Generators are one time use<br />&gt;&gt;&gt; c = countdown(5)<br />Traceback (most recent call last):<br />&nbsp; File "<pyshell>", line 1, in <module></module></pyshell><br />&nbsp; &nbsp; c = countdown(5)<br />NameError: name 'countdown' is not defined<br />&gt;&gt;&gt; ## to use generator repeatedly we can use class<br /><br />&gt;&gt;&gt; class Countdown(object):<br /><span style="white-space: pre;"> </span>def __init__(self, start):<br /><span style="white-space: pre;"> </span>self.start = start<br /><span style="white-space: pre;"> </span>def __iter__(self):<br /><span style="white-space: pre;"> </span>n = self.start<br /><span style="white-space: pre;"> </span>while n &gt; 0:<br /><span style="white-space: pre;"> </span>yield n<br /><span style="white-space: pre;"> </span>n -= 1<br /><br />&gt;&gt;&gt; c = Countdown(5)<br />&gt;&gt;&gt; for x in c:<br /><span style="white-space: pre;"> </span>print(x)<br /><br /><br />5<br />4<br />3<br />2<br />1<br />&gt;&gt;&gt; for x in c:<br /><span style="white-space: pre;"> </span>print(x)<br /><br /><span style="white-space: pre;"> </span><br />5<br />4<br />3<br />2<br />1<br />&gt;&gt;&gt;<br /><br />### Watching a real-time data source with a generator<br /><br />### Processing pipelines and workflows<br /><br />## Coroutines. Calling coroutines with async/wait<br /><br />&gt;&gt;&gt; async def greeting(name):<br /><span style="white-space: pre;"> </span>return 'Hello' + name<br /><br />&gt;&gt;&gt; g = greeting('Hello')<br />&gt;&gt;&gt; g<br /><coroutine 0x102b7dba0="" at="" greeting="" object=""></coroutine><br />&gt;&gt;&gt; ## co routine is a fucntion that works under the management is some code<br />&gt;&gt;&gt; import asyncio<br />&gt;&gt;&gt; loop = asyncio.get_event_loop()<br />&gt;&gt;&gt; loop.run_until_complete(g)<br />'HelloHello'<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; async def hello():<br /><span style="white-space: pre;"> </span>names = ['Nawraj','Lekhak']<br /><span style="white-space: pre;"> </span>for name in names:<br /><span style="white-space: pre;"> </span>print(await greeting(name))<br /><span style="white-space: pre;"> </span><br />&gt;&gt;&gt; h = hello()<br />&gt;&gt;&gt; h<br /><coroutine 0x10583cfc0="" at="" hello="" object=""></coroutine><br />&gt;&gt;&gt; loop.run_until_complete(h)<br />HelloNawraj<br />HelloLekhak<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt; async def fib(n):<br /><span style="white-space: pre;"> </span>if n &lt;= 2:<br /><span style="white-space: pre;"> </span>return 1<br /><span style="white-space: pre;"> </span>else:<br /><span style="white-space: pre;"> </span>return await fib(n-1) + await fib(n-2)<br /><br />&gt;&gt;&gt; f = fib(10)<br />&gt;&gt;&gt; f<br /><coroutine 0x10586e048="" at="" fib="" object=""></coroutine><br />&gt;&gt;&gt; loop.run_until_complete(f)<br />55<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br />&gt;&gt;&gt;<br /><br /></div></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com0tag:blogger.com,1999:blog-6880492769470667099.post-66052333508269333502017-09-29T13:00:00.004+05:302017-09-29T13:00:49.863+05:30Python Try and Except<div dir="ltr" style="text-align: left;" trbidi="on">try:<br /><span style="white-space: pre;"> </span>pass<br />except Exception:<br /><span style="white-space: pre;"> </span>pass<br />else:<br /><span style="white-space: pre;"> </span>pass<br />finally:<br /><span style="white-space: pre;"> </span>pass<br /><br />f = open('_comment.py')<br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; pass<br />except Exception:<br />&nbsp; &nbsp; &nbsp; &nbsp; pass<br /><br />try:<br /><span style="white-space: pre;"> </span>f = open('_comment.py')<br />except Exception: ## whatever is the error everytime it will print below message.<br /><span style="white-space: pre;"> </span>print('Sorry. the file does not exist')<br /><br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('comment.py')<br />&nbsp; &nbsp; &nbsp; &nbsp; var = bad_var<br />except Exception: ## let's provide correct file name. This too will print below error message<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Sorry. the file does not exist')<br /><br />## instead of exception we can say file not found error<br /><br />## this will only print name error<br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('comment.py')<br />&nbsp; &nbsp; &nbsp; &nbsp; var = bad_var<br />except FileNotFoundError:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Sorry. the file does not exist')<br /><br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('comment.py')<br />&nbsp; &nbsp; &nbsp; &nbsp; var = bad_var<br />except FileNotFoundError:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Sorry. the file does not exist')<br />except Exception:<br /><span style="white-space: pre;"> </span>print('Sorry. Something went wrong')<br /><br />## instead of printing custom message let's print exception<br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('comment.py')<br />&nbsp; &nbsp; &nbsp; &nbsp; var = bad_var<br />except FileNotFoundError as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />except Exception as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br /><br /># lets remove bad_var. it runs without any error<br /><br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('comment.py')<br />except FileNotFoundError as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />except Exception as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br /><br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('_comment.py')<br />except FileNotFoundError as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />except Exception as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br /><br />## if try doesn't run any exception, else section will execute. This will read file<br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('comment.py')<br />except FileNotFoundError as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />except Exception as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />else:<br /><span style="white-space: pre;"> </span>print(f.read())<br /><span style="white-space: pre;"> </span>f.close()<br />## code under else can be placed under try statement as well but it wise not to do that<br /><br />## finally runs whether code is successful or not. This execute else as well as finally section<br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('comment.py')<br />except FileNotFoundError as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />except Exception as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />else:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(f.read())<br />&nbsp; &nbsp; &nbsp; &nbsp; f.close()<br />finally:<br /><span style="white-space: pre;"> </span>print("Executing finally")<br /><br />## let's place wrong file. this will catch exception and execute finally section<br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('_comment.py')<br />except FileNotFoundError as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />except Exception as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />else:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(f.read())<br />&nbsp; &nbsp; &nbsp; &nbsp; f.close()<br />finally:<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Executing finally")<br /><br />## we can raise exception on our own ie manually<br />try:<br />&nbsp; &nbsp; &nbsp; &nbsp; f = open('apr-24.txt')<br />&nbsp; &nbsp; &nbsp; &nbsp; if f.name == 'apr-24.txt':<br /><span style="white-space: pre;"> </span>raise Exception<br />except FileNotFoundError as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(e)<br />except Exception as e:<br />&nbsp; &nbsp; &nbsp; &nbsp; print('Error!')<br />else:<br />&nbsp; &nbsp; &nbsp; &nbsp; print(f.read())<br />&nbsp; &nbsp; &nbsp; &nbsp; f.close()<br />finally:<br />&nbsp; &nbsp; &nbsp; &nbsp; print("Executing finally")<br /><br /><br /><br /><br /><br /><br /></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com0tag:blogger.com,1999:blog-6880492769470667099.post-67587507379928851082017-09-29T12:57:00.003+05:302018-09-10T17:43:27.923+05:30Python decorators<div dir="ltr" style="text-align: left;" trbidi="on"><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">class Car:<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def __init__(self):<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("Car object created.")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def drive():<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("driving a car..")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c = Car()<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c.drive() ## this is equivalent to Car.drive(c) but this will work<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">Car.drive()<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;verdana&quot; , sans-serif; font-size: 11.0pt;">TypeError:&nbsp;drive()&nbsp;takes&nbsp;0&nbsp;positional&nbsp;arguments&nbsp;but&nbsp;1&nbsp;was&nbsp;given</span><o:p></o:p></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">Solution is @staticmethod. With staticmethod we don't have to initialize object. staticmethod doesn't need any object we can call method directly from class and staticmethod cannot access class attributes.<o:p></o:p></span><br /><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><br /></span><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">Car.drive()</span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">class Car:<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def __init__(self):<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("Car object created.")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>@staticmethod<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def drive():<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("driving a car..")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c = Car()<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c.drive()<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">output:<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">Car object created.<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">driving a car..<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">======</span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">class Car:<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def __init__(self):<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("Car object created.")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>@staticmethod<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def drive():<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("driving a car..")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>#@classmethod<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def sell(c):<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;</span><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("c =", c)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c = Car()<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c.drive()<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c.sell()<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">Car object created.<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">driving a car..<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">c = <__main__ .car="" 0x7fda7b572b00="" at="" object=""><o:p></o:p></__main__></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">to make it work, use classmethod<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">class Car:<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def __init__(self):<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("Car object created.")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>@staticmethod ## we don’t pass anything<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def drive():<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("driving a car..")<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>@classmethod ## always take class as first argument<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def sell(c):<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;</span><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>print("c =", c)<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c = Car()<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c.drive()<o:p></o:p></span></div><div class="MsoNormal"><span lang="EN-US" style="color: black; font-family: &quot;menlo&quot;; font-size: 11.0pt;">c.sell() or Car.sell()<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">output:<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">Car object created.<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">driving a car..<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">c = <class main__.car=""><o:p></o:p></class></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">staticmethod pass nothing whether u call from class or instance. It will call function as it is. Staticmethod cannot access class or instance attribute. <o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">classmethod: whether you call for class perspective or instance perspective always it will call class as first argument<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">decorator is a pattern which allows one function or object to decorate another object <o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">def greet():<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>return "Hello world"<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">def convert_to_upper(fn):<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def wrapper():<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>return fn().upper()<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>return wrapper<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">print("greet =", greet)<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">print(greet())<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">greet = convert_to_upper(greet)<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">print("greet =", greet)<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">print(greet())<span style="color: #e93f34;"><o:p></o:p></span></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">output:<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">greet = <function 0x7f790d200f28="" at="" greet=""><o:p></o:p></function></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">Hello world<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">greet = <function convert_to_upper.="" locals="">.wrapper at 0x7f790d200e18&gt;<o:p></o:p></function></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">HELLO WORLD<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">Actual code should be:<o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">def convert_to_upper(fn):<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>def wrapper():<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>return fn().upper()<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>return wrapper<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">@convert_to_upper<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">def greet():<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>return "Hello world"<span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">print("greet =", greet)<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; font-family: &quot;calibri&quot; , sans-serif; font-size: 11pt;">print(greet())<span style="color: #e93f34;"><o:p></o:p></span></span></div><div class="MsoNormal"><br /></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">##output<o:p></o:p></span></div><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">greet = <function convert_to_upper.="" locals="">.wrapper at 0x7f692a474e18&gt;<o:p></o:p></function></span></div><!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" DefPriority="99" LatentStyleCount="375"> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 9"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="header"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footer"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index heading"/> <w:LsdException Locked="false" Priority="35" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of figures"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope return"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="line number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="page number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of authorities"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="macro"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="toa heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 5"/> <w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Closing"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Signature"/> <w:LsdException Locked="false" Priority="1" SemiHidden="true" UnhideWhenUsed="true" Name="Default Paragraph Font"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Message Header"/> <w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Salutation"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Date"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Note Heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Block Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="FollowedHyperlink"/> <w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Document Map"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Plain Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="E-mail Signature"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Top of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Bottom of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal (Web)"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Acronym"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Cite"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Code"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Definition"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Keyboard"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Preformatted"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Sample"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Typewriter"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Variable"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Table"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation subject"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="No List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Contemporary"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Elegant"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Professional"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Balloon Text"/> <w:LsdException Locked="false" Priority="39" Name="Table Grid"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Theme"/> <w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> <w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/> <w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/> <w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/> <w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/> <w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/> <w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Mention"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Smart Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hashtag"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Unresolved Mention"/> </w:LatentStyles></xml><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-536870145 1107305727 0 0 415 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-536859905 -1073732485 9 0 511 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1593833729 1073750107 16 0 415 0;} @font-face {font-family:Menlo; panose-1:2 11 6 9 3 8 4 2 2 4; mso-font-charset:0; mso-generic-font-family:modern; mso-font-pitch:fixed; mso-font-signature:-436198657 -771687941 33554472 0 479 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman",serif; mso-fareast-font-family:"Times New Roman";} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} </style></div>--&gt; <!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style><![endif]--> <!--StartFragment--> <!--EndFragment--><div class="MsoNormal"><span style="background: white; color: #e93f34; font-family: &quot;calibri&quot; , sans-serif; font-size: 11.0pt;">HELLO WORLD<o:p></o:p></span></div><br /><br />def outer_function():<br /><span style="white-space: pre;"> </span>message = 'Hi'<br /><br /><span style="white-space: pre;"> </span>def inner_function():<br /><span style="white-space: pre;"> </span>print(message)<br /><span style="white-space: pre;"> </span>return inner_function()<br /><br />outer_function()<br /><br />def outer_function():<br />&nbsp; &nbsp; &nbsp; &nbsp; message = 'Hi'<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; def inner_function():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(message)<br />&nbsp; &nbsp; &nbsp; &nbsp; return inner_function<br /><br />my_func = outer_function()<br />my_func()<br />my_func()<br />my_func()<br /><br />def outer_function(msg):<br />&nbsp; &nbsp; &nbsp; &nbsp; message = msg<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; def inner_function():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(message)<br />&nbsp; &nbsp; &nbsp; &nbsp; return inner_function<br /><br />hi_func = outer_function('Hi')<br />bye_func = outer_function('Bye')<br />hi_func()<br />bye_func()<br /><br />def outer_function(msg):<br />&nbsp; &nbsp; &nbsp; &nbsp; def inner_function():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(msg)<br />&nbsp; &nbsp; &nbsp; &nbsp; return inner_function<br /><br />hi_func = outer_function('Hi')<br />bye_func = outer_function('Bye')<br />hi_func()<br />bye_func()<br /><br />## all of above code is on closure. Now let's talk about decorator. It is similar to closure.<br />## a decorator is a function that takes another function as argument, adds some kind of functionality and return another function all of this without altering the source code of original function passed in<br /><br />## lets repalce outer function with decorator and inner function with wrapper.Instead of message we are going to accept function as argument<br /><br />def decorator_function(original_function):<br /><span style="white-space: pre;"> </span>def wrapper_function():<br /><span style="white-space: pre;"> </span>return original_function()<br /><span style="white-space: pre;"> </span>return wrapper_function<br /><br />def display():<br /><span style="white-space: pre;"> </span>print('display function ran')<br /><br />decorated_display = decorator_function(display)<br />decorated_display()<br /><br />## here decorated_display is equal to wrapper function<br /><br />## decorator function allows us to easily add functionality to our existing function by adding that functionality inside our wrapper function<br /><br />def decorator_function(original_function):<br />&nbsp; &nbsp; &nbsp; &nbsp; def wrapper_function():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('wrapper executed this before {}'.format(original_function.__name__))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return original_function()<br />&nbsp; &nbsp; &nbsp; &nbsp; return wrapper_function<br /><br />def display():<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display function ran')<br /><br />decorated_display = decorator_function(display)<br />decorated_display()<br /><br />## or<br /><br />def decorator_function(original_function):<br />&nbsp; &nbsp; &nbsp; &nbsp; def wrapper_function():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('wrapper executed this before {}'.format(original_function.__name__))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return original_function()<br />&nbsp; &nbsp; &nbsp; &nbsp; return wrapper_function<br /><br />@decorator_function<br />def display():<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display function ran')<br /><br />display()<br /><br />#@decorator_function is equal to display = decorator_function(display)<br />## Now let's decorate two functions with same decorator<br /><br />def decorator_function(original_function):<br />&nbsp; &nbsp; &nbsp; &nbsp; def wrapper_function(*args, **kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('wrapper executed this before {}'.format(original_function.__name__))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return original_function(*args, **kwargs)<br />&nbsp; &nbsp; &nbsp; &nbsp; return wrapper_function<br /><br />@decorator_function<br />def display():<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display function ran')<br /><br />@decorator_function<br />def display_info(name,age):<br /><span style="white-space: pre;"> </span>print('display_info ran with arguments ({}, {})'.format(name, age))<br /><span style="white-space: pre;"> </span><br />display_info('Nawraj', 32)<br /><br />display()<br /><br />## We can also use class as decorator instead of function<br /><br />class decorator_class(object):<br /><span style="white-space: pre;"> </span>def __init__(self, original_function):<br /><span style="white-space: pre;"> </span>self.original_function = original_function ## tie our function with the instance of this class<br /><br /><span style="white-space: pre;"> </span>## instead of wrpper function we need to use call method here<br /><span style="white-space: pre;"> </span>def __call__(self, *args, **kwargs):<br /><span style="white-space: pre;"> </span>print('call method executed this before {}'. format(self.original_function.__name__))<br /><span style="white-space: pre;"> </span>return self.original_function(*args, **kwargs)<br /><br />@decorator_class<br />def display():<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display function ran')<br /><br />@decorator_class<br />def display_info(name,age):<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display_info ran with arguments ({}, {})'.format(name, age))<br /><br />display_info('Nawraj', 32)<br />display()<br /><br />## some practical examples<br />def my_logger(orig_func):<br /><span style="white-space: pre;"> </span>import logging<br /><span style="white-space: pre;"> </span>logging.basicConfig(filename='{}.log'.format(orig_func.__name__), level=logging.INFO)<br /><br /><span style="white-space: pre;"> </span>def wrapper(*args, **kwargs):<br /><span style="white-space: pre;"> </span>logging.info(<br /><span style="white-space: pre;"> </span>'Ran with args: {}, and kwargs: {}'.format(args, kwargs))<br /><span style="white-space: pre;"> </span>return orig_func(*args, **kwargs)<br /><span style="white-space: pre;"> </span>return wrapper<br /><br />def my_timer(orig_func):<br /><span style="white-space: pre;"> </span>import time<br /><br /><span style="white-space: pre;"> </span>def wrapper(*args, **kwargs):<br /><span style="white-space: pre;"> </span>t1 = time.time()<br /><span style="white-space: pre;"> </span>result = orig_func(*args, **kwargs)<br /><span style="white-space: pre;"> </span>t2 = time.time() - t1<br /><span style="white-space: pre;"> </span>print('{} ran in: {}'.format(orig_func.__name__, t2))<br /><span style="white-space: pre;"> </span>return result<br /><span style="white-space: pre;"> </span>return wrapper<br /><br />#@decorator_function<br />#def display():<br />#&nbsp; &nbsp; &nbsp; &nbsp; print('display function ran')<br /><br />@my_logger<br />def display_info(name,age):<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display_info ran with arguments ({}, {})'.format(name, age))<br /><br />#display_info('Nawraj', 32)<br />## this will create a display_info.log file<br /><br />## we can add this logging functionaltiy to any new function using this decorator. We don't have to add logging functionality to all new functions<br /><br />## Now lets use timer decorator<br />import time<br />@my_timer<br />def display_info(name,age):<br />&nbsp; &nbsp; &nbsp; &nbsp; time.sleep(1)<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display_info ran with arguments ({}, {})'.format(name, age))<br />display_info('Nawraj', 32)<br /><br />## we can also use two decorator to decorate same function<br />def my_logger(orig_func):<br />&nbsp; &nbsp; &nbsp; &nbsp; import logging<br />&nbsp; &nbsp; &nbsp; &nbsp; logging.basicConfig(filename='{}.log'.format(orig_func.__name__), level=logging.INFO)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; def wrapper(*args, **kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logging.info(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Ran with args: {}, and kwargs: {}'.format(args, kwargs))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return orig_func(*args, **kwargs)<br />&nbsp; &nbsp; &nbsp; &nbsp; return wrapper<br /><br />def my_timer(orig_func):<br />&nbsp; &nbsp; &nbsp; &nbsp; import time<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; def wrapper(*args, **kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1 = time.time()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = orig_func(*args, **kwargs)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2 = time.time() - t1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('{} ran in: {}'.format(orig_func.__name__, t2))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return result<br />&nbsp; &nbsp; &nbsp; &nbsp; return wrapper<br /><br />import time<br /><br />@my_logger<br />@my_timer<br />def display_info(name,age):<br />&nbsp; &nbsp; &nbsp; &nbsp; time.sleep(1)<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display_info ran with arguments ({}, {})'.format(name, age))<br /><br />display_info('Nawraj', 32)<br /><br /># note:<br />@my_logger<br />@my_timer<br />is equivalent to display_info = my_logger(my_timer(display_info))<br />first my_timer will execute and then my_logger<br /><br />## to preserve the identity of original function in case of nested decorator we use wraps to decorate all our wrapper<br />from functools import wraps<br /><br />def my_logger(orig_func):<br />&nbsp; &nbsp; &nbsp; &nbsp; import logging<br />&nbsp; &nbsp; &nbsp; &nbsp; logging.basicConfig(filename='{}.log'.format(orig_func.__name__), level=logging.INFO)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; @wraps(orig_func)<br />&nbsp; &nbsp; &nbsp; &nbsp; def wrapper(*args, **kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logging.info(<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Ran with args: {}, and kwargs: {}'.format(args, kwargs))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return orig_func(*args, **kwargs)<br />&nbsp; &nbsp; &nbsp; &nbsp; return wrapper<br /><br />def my_timer(orig_func):<br />&nbsp; &nbsp; &nbsp; &nbsp; import time<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; @wraps(orig_func)<br />&nbsp; &nbsp; &nbsp; &nbsp; def wrapper(*args, **kwargs):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1 = time.time()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = orig_func(*args, **kwargs)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2 = time.time() - t1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print('{} ran in: {}'.format(orig_func.__name__, t2))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return result<br />&nbsp; &nbsp; &nbsp; &nbsp; return wrapper<br /><br />import time<br /><br />@my_logger<br />@my_timer<br />def display_info(name,age):<br />&nbsp; &nbsp; &nbsp; &nbsp; time.sleep(1)<br />&nbsp; &nbsp; &nbsp; &nbsp; print('display_info ran with arguments ({}, {})'.format(name, age))<br /><br />display_info('Nawraj', 32)<br /><div><br /></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com0tag:blogger.com,1999:blog-6880492769470667099.post-60267918851196731332017-08-17T14:13:00.001+05:302018-02-04T19:33:19.950+05:30Certified Information Systems Security Professional (CISSP)<div dir="ltr" style="text-align: left;" trbidi="on"><div class="p1"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Applying cryptography</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">encryption for confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">hashed for integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">digitally signed certificates for authentication</span></div><div class="p3"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="s1" style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">digital signatures can be used to ensure non-repudiation</span></span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="s1" style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></span> <span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="s1">(</span><span class="s2"><b>Nonrepudiation</b>&nbsp;is the assurance that someone cannot deny something.</span><span class="s1">)</span></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">cryptography : Science of secret writing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Authentication: Proves idenitiy</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">nonrepudiation: Proves sender</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cipher: cryptographic set of rules or technique</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ciphertext: transformed plaintext to unreadable form</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Algorithm: Complex mathematical cipher</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Key: crypto variable used with an algorithm</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Keyspace: Number of possible key combinations</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Encryption types:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Substitution : Replacing characters or bits</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Transposition : Moving characters or bits</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">key stream: One bit at a time XOR function</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Confusion: multiple rounds of substitution</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Diffusion : multiple rounds of transposition</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">3 DES :<span class="Apple-converted-space">&nbsp; </span>uses data encryption algorithm and 48 rounds</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">AES : used Rijndael and 3 key size options</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">DES: 16 round block symmetric algorithm</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Keys:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">symmetric : single shared key</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">asymmetric: key pair</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">session key : specific instance of symmetric key</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">ECC, RSA,EIGamel :asymmetric algorithm</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">AES,3DES,IDEA : symmetric key standard and algorithms</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">PKI:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Registration authority: manages digital certificates</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Certificate authority: Issues and revoke digital certificates</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Digital certificate: Identifier with embedded public key</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">X.509: ISO PKI standard framework</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Public key: key that is distributed</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Private key: key that is kept secure</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">CRL: certificate revocation list</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">OCSP: certificate revocation protocol</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Hashing: Producing a one-way representation</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Message digest: output of a hash function</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SHA-x : NSA developed hash algorithm</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">HMAC: hash output with a symmetric key</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Digital SIgnature: Digest encrypt its private key</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">DSA: Digital signature algorithm</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Nonrepudiation: Proves sender</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Salt: A rehash value added to a database</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Link encryption: Payload + header encryption</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">End-to-end encryption: payload only encryption</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">IPsec: de facto vpn protocol</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL/TLS: application layer cryptographic protocol</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">HTTPS: hyper text transfer protocol + SSL/TLS</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSH: used for secure remote authentication</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SFTP : used for secure file transfer</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">S/MIME: use for secure email</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Side channel attack: Measure execution time or power</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">brute force attack: Exhausting all possibilities</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">frequency analysis: looking for patterns</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">collision: Different input results in same hash values</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">birthday attack: Exploits probability to produce collisions</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">MiTM : Interception and modification</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Replay: Capture and re-transmit</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Crypto-retirement : DES (End of life)</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL/TLS</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL/TLS protocol is a set of rules governing client and server authentication and encrypted communications.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL/TLS requires the server to have a SSL digital certificate:</span></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The server authenticates itself to the client and provides its public keys (used to encrypt the session key)</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The client and server uses symmetric-key encryption to encryption the information exchanged in the session.</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The server may be optionally configured to require client-side authentication before an encrypted session can be established.</span></li></ul><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Secure Shell</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Secure Shell (SSH) is a cross-platform cryptographic protocol that establishes a secure connection between an SSH server and an SSH client supporting asymmetric authentication, message authentication code and symmetric encryption.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSH is used to administer systems remotely, provide a command shell on a remote network or tunnel other protocols.</span></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">ssh is a replacement for cleartext telnet, login, rsh, and rsync</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SFTP is a file transfer protocol that uses SSH to transfer files.</span></li></ul><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Internet Protocol Security (IPsec):</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec is a suite of protocols that used cryptographic security services to protect communications over internal protocol (IP) networks.</span></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec supports:</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">network-level peer authentication</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">data origin authentication</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">data integrity</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">data confidentiality(encryption)</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">replay protection</span></li></ul><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Eavesdropping : violation of confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Tampering: violation of integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Spoofing: violation of authenticity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL/TLS : Secure client-server communication</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSH : secure telnet replacement</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">S/MIME: Used to digitally sign email</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Encryption: used to ensure confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Digital Signatures : MD encrypted with private key</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">NAT :</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">NAT is a stateful process used by the firewall to change the source IP address of outgoing packets.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">NAT can be used to:</span></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Anonymize(hide) internal address</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Transform non routable ip address to routable addresses</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Extend IPv4 address space</span></li></ul><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">NAT mapping can be static, dynamic or PAT</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Honeypots and Honeynets:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Honeypots are decoy(luring) servers or systems set up to gather information regarding attacks or intrusions.</span></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Honeypots work by fooling attackers into believing it is a legitimate system.</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Attackers attack the system without knowing that they are being observed covertly.<span class="Apple-converted-space">&nbsp;</span></span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Honeypots can be set up inside, outside, or in the DMZ of a firewall</span></li></ul><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Honeynets are the networks of Honeypots</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">DMZ: Semi-trusted network segment</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Enclave network: Segment within a trusted network</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Honeypot: research decoy</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Firewall: Enforces security policies</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">IDS/IPS: detective and corrective control</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">NAT: used to translate internal ip address</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">False positive: normal identified as abnormal</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Proxy: Acting on behalf of<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Securing multimedia collaboration:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">IP telephony: Telecommunications services using IP</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SIP: use MD5, TLS, and privacy extensions</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">RTP: requests redelivery of VOIP packets</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Codec: conversion of audio/video to digital frames</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">H.323 : First widely adopted VOIP protocol</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SIP redirect server : Facilities SIP device portability</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SIP registrar server : facilities SIP user portability</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">CDN: High performance content distribution</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Securing virtual private networks:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">VPN technologies includes:</span></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Point to point tunnelling protocol (PPTP)</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Layer 2 tunneling protocol (L2TP)</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Internet protocol security (IPsec)</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Secure Socket layer (SSL)</span></li></ul><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec Modes:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec can be implemented in two modes:</span></div><ul class="ul2"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Transport mode is used for end-to-end protection between client and server</span></li><ul class="ul3"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The IP payload is encrypted</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Transport is the default mode of Ipsec</span></li></ul><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Tunnel mode is used between server-server, server-gateway, or gateway-gateway (two direct endpoints)</span></li><ul class="ul3"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The entire packet is encrypted</span></li></ul></ul><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec components :</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">AH : Integrity, Origin Authentication, Replay Attack protection (HAMC)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">ESP : Integrity, Origin Authentication, Replay Attack protection and Confidentiality (HMAC &amp; Symmetric encryption)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">IKE : Device authentication and establishing security association</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SA : A negotiation that includes the algorithms that will be used (hashing and encryption), key length, and key information</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SPI : Security association identifier</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec uses AH and ESP</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec Key Exchange:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Phase 1 : device authentication</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Phase 2 : establish secure tunnel</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec security Parameter Index (SPI)</span></b></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Security associations are identified by a security parameter index (SPI)</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Two separate SAs are established for each direction of data communication</span></li></ul><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec Security Filters</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ipsec filters can be used to filter (allow, restrict, and secure) traffic by source IP, destination IP, protocol, source port and destination port</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL VPN</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">ssl vpn communicates at the OSI transport and session layer</span></div><ul class="ul1"><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A user connects to an SSL gateway or endpoint using a web browser. SSL/TLS capabilities are embedded in most of web browsers.</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The traffic is encrypted with SSL/TLS</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">An SSL VPN portal is a single connection to multiple services.</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The user is authenticated by a SSL VPN gateway</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The user is presented a web page</span></li><li class="li2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The SSL VPN tunnel is used to access non web-based applications</span></li></ul><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">VPN Comparisons:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">PPTP : used when a PPP connection needs to be transmitted through a IP network</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">L2TP : used when a PPP connection needs to be transmitted through a non-IP network</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">IPSec: used for IP based traffic</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">HAIPE : used for high-security IPSec implementations</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL VPN : mainly used for http traffic</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">PPTP: used to secure PPP on a IP network</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">L2TP: can be used on a non-IP network</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Transport mode: Payload is encrypted</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Tunnel mode: entire packet is encrypted</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">AH: Integrity and authentication only</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">ESP : integrity, authentication and confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Security Association : IPSec negotiated agreement</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL VPN: uses client side browser</span></div><div class="p1"><span class="Apple-tab-span" style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"> </span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Securing Endpoints</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">NAC (network access control): Unified endpoint security enforcement</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Proxy: Acts on behalf of endpoint</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">MDM(Mobile device management) : Usually includes a remote wipe feature</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Malware : Code or script with malicious intent</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">HIDS(Host IDS): Monitors and analyses local host behaviour</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Preventing and mitigating network attacks:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Opportunistic: influenced by an identified weakness</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Spoofing: Impersonation</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Poisoning: manipulating trusted data</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">MiTM: interjection between end points</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Sniffing: Capturing network packets</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Ransomware : class of malware</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">C&amp;C: Command and control</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">DDos : Distributed consumption of resources</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">OSI Model : Seven layers of communication</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">TCP/IP Model: Four layers of connectivity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">ARP : MAC to IP translation</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">IPv4: 32bit 4 octet ID</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">IPv6: 128-bit hexadecimal ID</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Port : application ID</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Well-known ports: 1-1023</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">DNSSEC: extensions to mitigate forged entries</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">VOIP : Transmission of voice traffic over IP</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">MPLS: Protocol-independent telecom support</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">DNP3: Process automation communications</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SIP: Protocol used on VOIP networks</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">LER: Router used in a MPLS networks</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Label: Replacement for a header in MPLS</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">FCoE : storage area network data channel over IP</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Securing wireless networks</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">bluejacking : Injection attack</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">bluesnarfing: Unauthorized access</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">war driving : Hacking wireless networks</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">ad hoc mode: peer-to-pper connectivity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">WEP : Broken encryption, no integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">WPA2 : uses 802.1x, EAP, AES, and CBC-MAC</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">WWAN: uses point to point microwave links</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">GSM &amp; CDMA : Cellular technologies</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Security testing</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Brute force : Trying every possible combination</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Dictionary attack : Compares two sets of hashes</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Work factor : Time and effort required</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Hash : One-way fixed length fingerprint</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Salt: Random string appended before hashing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Reverse lookup : Technique that assumes same input</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Symmetric encryption : same key used to encrypt and decrypt</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">HMAC : hash value that includes a secret key</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Operating and maintaining firewalls:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">GeoIP : Ip address geographic location or range</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Deny by default : Must be explicitly allowed</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Allow by default : must be explicitly denied</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Whitelist : known benign - proactively allowed</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Blacklist : known malicious - proactively denied</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Sanitation : Remove sensitive information</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Sandbox: isolated environment</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Honeypot : Decoy system</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Source code security issues:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Buffer overflow : Overrun of allocated memory</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Injection attack : Accepts and executes untrusted input</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Convert channel: unauthorised flow of information</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">object reuse attack: Malicious repurpose of code</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">TOC|TOU : Race condition</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Maintenance hook: Mechanism to bypass access controls</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Fuzzing: Testing technique that uses invalid data</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">OAuth: Open authorisation protocol</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Deciphering Ciphers and Algorithms</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cipher is a technique or set of rules that transforms cleartext(plaintext) into an unreadable form(cipher text or cryptogram) and back to cleartext</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Algorithm is a set of steps to accomplish a task</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Key(Cryptovariable)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- The key dictates what parts of the algorithm will be used, in what order, and with what values</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- The key is secret</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- keyspace is the number of possible key combinations</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>. 8 bit = 2*8 = 256 possible keys</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>. 256bit = 2*256 = 1.1.578*1077 possible keys</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cipher Characteristics</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">1. Stream</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>Stream cipher encodes the bits one at a time using a XOR key stream generator(resource-intensive)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>-RC4 is the most well-known stream cipher.</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">2. Block<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Substitution</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Transposition</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>Block cipher breaks the plaintext message into several blocks</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>- A block cipher algorithm puts the bits within these blocks through several rounds of substitution and transposition. The goal is <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>confusion(changing values) and diffusion(changing order.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>- Electronic Codebook Mode (ECB) each block is independent (doesn’t hide patterns - not suitable for long messages)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>- Cipher Block Chaining Mode(CBC) includes an initialization vector and a component of the previous cipher text to leverage randomization</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Block ciphers null : DES, 3DES, AES, IDEA, Blowfish, RC5, RC6, Skipjack, CAST</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">symmetric and asymmetric encryption:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">symmetric means the same key is used to encrypt and decrypt</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">also referred as<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- single key</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- shared key</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- session key(if used for a single session)</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">computationally efficient</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">key sharing is null</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">not scalable<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Asymmetric means two different but related keys are used :</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- known as key-pair</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- one key is used for encrypt; the other is used to decrypt</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- The keys are referred as a private and public key</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">computationally intensive</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">smaller key sizes</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">null distribution system</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">scalable</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Applying asymmetric encryption:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Since it is computationally intensive, in most cases we use both symmetric and asymmetric keys (also known as hybrid)</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Plaintext message<span class="Apple-converted-space">&nbsp; </span>- &gt; symmetric cipher [session key] -&gt; encrypted message - &gt; symmetric cipher [session key] -&gt; plaintext message</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">but the problem here is how to share session key between Bob and Alice. To accomplish this we use asymmetric algorithm</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">session key - &gt; Asymmetric Cipher + Alice</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">now Alice can use this session key to decrypt original message in first case.</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Understanding hashing:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A hash is a one-way representation (fingerprint) of a string of text</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- A hash function takes input of any length and creates a fixed length output</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Hash value is used to prove integrity</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Hash algorithms examples</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Message Digest (Mdx), Secure hash algorithm (SHA), Havel, Tiger</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Hash Process</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">sender puts message through<span class="Apple-converted-space">&nbsp; </span>a hashing algorithm and generates a message digest (hash) value -&gt; sender sends plain text message and message digest to receiver - &gt; receiver puts message through a hashing algorithm and generates a message digest(hash) value -&gt; Receiver compares both message digests -&gt; if the message digests are the same - the message was not modified in transmission - &gt; if the message digest are different - the message was modified in transmission</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">sender<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">hello, this is my message + run thorough SHA-2 = 1HFBK2FR7</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Receiver :</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">receiver gets original message and hashed output ie message digest (1HFBK2FR7)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">it runs through same algorithm SHA-2 and output should be : 1HFBK2FR7</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">if outputs are same, message is not modified during transmission.</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Hashed MAC</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A hashed message authentication code(HMAC) is hashed value that includes a symmetric key.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- An HAMC cannot be reproduce without knowing the key.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- HAMC provides integrity and data origin authentication</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- HMAC is used by cryptographic protocols such as the TLS and IPsec to verify the integrity of transmitted data during secure communications</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">HMAC process:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Sender concatenates message + secret key and puts the results through a hashing algorithm and generates a HMAC value -&gt;Sender appends the HAMC value to the message and sends it to the receiver -&gt; Receiver concatenates messages + secret key and puts a results through a hashing algorithm and generates a HMAC value -&gt; Receiver compares both values -&gt; if the values are the same then the message was not modified in transmission and the origin is known</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">This will accomplish both integrity and confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Sender :</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">hello, this is my message + secret key (1234567) + run through SHA-2 = 79HVGRST</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Receiver:</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">it gets original message and message digest output i.e. 79HVGRST</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Receiver needs to have knowledge of secret key (1234567) it is not send by sender</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">run this message and secret key through same SHA-2 algorithm, output should be same.</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Digital Signatures:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A digital signature is a hash value (message digest) encrypted with the sender’s private key.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- A digital signature provides integrity and non-repudiation</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Digital signatures require two algorithms:</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Hashing algorithm (e.g. SHA-x)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Digital signature function such as RSA or DSA (Digital signature algorithm)</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Digitally signed message:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Bob creates a message digest(hash value) of his message -&gt; The message digest is encrypted with Bob’s private key -&gt; The encrypted message digest and plaintext message are sent to Alice -&gt; Alice decrypts the message digest using Bob’s public key (providing non-repudiation) -&gt; Alice hashes the plaintext message using the same hash algorithm -&gt; Alice compares the two hash values for a match (proving integrity)</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Integrity(not changed during transmission), Confidentiality(only authorized person can see message) and non-repudiation (can’t deny it came from you)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- A message can be hashed, which provides for integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- A message can be digitally signed, which provides for non-repudiation and integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- A message can be encrypted, which provides for confidentiality.</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- A message can be encrypted and digitally signed, which provides for confidentiality, nonrepudiation and integrity.</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Deconstructing the Digital certificate lifecycle</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A digital certificate is an electronic “passport” that identifies a person, device, domain. organization, or publisher (code).</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- The certificate is issued by a trusted certification authority, a web of trust or self-signed.</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">X.509 v3 digital certificates fields</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">version : version of certificate</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">serial number : unique identifier</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Signature : Algorithm used to sign the certificate</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Issuer : Name of issuer</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Validity: valid data of cert</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Subject : Name of owner</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Public key : Public<span class="Apple-converted-space">&nbsp; </span>key of named owner</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Issuer Unique id : ID of certificate authority</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Subject unique id : ID of subject</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Obtaining a Digital Certificate:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Applicant requests a certificate from a Registration Authority (RA) -&gt;</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The RA process the request and validates the applicant -&gt;</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The RA forward the request to a certification Authority (CA) -&gt;</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The CA requests the public key from the applicant -&gt;</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The key-pair is locally generated and the public key is sent to the CA -&gt;</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The CA creates and signs the digital certificate -&gt;<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The certificate includes the public key -&gt;</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The CA issues the digital certificate to the applicant -&gt;</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">The CA maintains and, if necessary, revokes the certificate</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Digital certificate Revocation:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Certificate revocation list (CRL)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- CA maintained list of certificates that have been revoked</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Online certificate status Protocol (OCSP)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Client receives certificate</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Client sends OCSP request to a OCSP responder</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- OCSP responder replies with a certificate status</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Both are only enforced for extended validation (EV) certificates</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Understanding Cryptographic Protocols:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cryptographic communication protocols (rules) are designed to secure information flow</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Information flow is vulnerable to<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Eavesdropping and packet capture, which is a violation of confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Tampering which is violation of intergrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Spoofing and misrepresentation, which can be a violation of authentication, integrity, and availability</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Transmission Modes</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Link Encryption</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- All control information (header, trailers, and routing information) is encrypted along with the payload</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">needs dedicated communication channel between A and B</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">End-to-end encryption</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- only the payload is encrypted</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Intermediary devices do not have encryption related functions</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">communication channel in this case is public i.e. internet. Trailer, header and routing information is visible.</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Common cryptographic Protocols:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSL | TLS :<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Use : Securing web based protocols and transmissions,</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Purpose : confidentiality, Authentication, Integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cryptographic components : Encryption, HAMC</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">HTTPS :<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Use: layer SSL | TLS on top of HTTP</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Purpose : confidentiality, Authentication, Integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cryptographic components : Encryption, HAMC</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">FTPS :<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Use : layer SSL | TLS on top of FTP</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Purpose : confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cryptographic components : Encryption</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SSH :<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Use:<span class="Apple-converted-space">&nbsp; </span>Secure channel between a local an remote device (telnet replacement)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Purpose: confidentiality, Integrity</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cryptographic components : Encryption, HAMC</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">SFTP:<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Use : Layer SSH on top of FTP</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Purpose : confidentiality</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cryptographic components : Encryption</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">S/MIME:<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Use: Secure email communications</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Purpose : confidentiality, Integrity, Nonrepudiation</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Cryptographic components : Encryption, HAMC</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Non-IP networking Protocols:</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- MPLS : operates in between L2 and L3</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- DNP3 : L2 protocol</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- FCoE<span class="Apple-converted-space">&nbsp; </span>: L2 protocol<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Attacks techniques</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Scanning: probing for information</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Sniffing: Packet capture</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Poisoning : Manipulating trusted data</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Spoofing : Impersonation</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Session Hijacking : Unauthorized insertion</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Sniffing can happen at any layer of OSI model</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Application: user id/password sniffing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Presentation: SSL/TLS session sniffing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Session:Telnet and FTP sniffing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Transport: TCP session sniffing, UDP sniffing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Network:IP, Port sniffing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Datalink :MAC/ARP sniffing</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Physical:Surveillance sniffing</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Poisoning:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A poisining attack is when a trusted source of data is manipulated:</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- ARP cache</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Routing table</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- DNS pharming</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">- Website</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Session Hijacking:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A session hijacking attack intercepts communication between two systems</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Man in middle (may use spoofing and/or poisoning)</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Replay Attack</span></div><div class="p1"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></b></div><div class="p2"><b><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">Spoofing:</span></b></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;">A spoofing attack is when an attacker impersonates(pretend to be) an address, system, or person</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- MAC address</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- IP address</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Domain</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Hyperlink</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Email sender</span></div><div class="p2"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><span class="Apple-tab-span"> </span>- Trusted source</span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;georgia&quot; , &quot;times new roman&quot; , serif;"><br /></span></div><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; background-color: #ffffff; min-height: 17.0px} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; background-color: #ffffff} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Arial; color: #222222; background-color: #ffffff} li.li2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; background-color: #ffffff} span.s1 {font: 14.0px Verdana; color: #000000} span.s2 {font-kerning: none} span.Apple-tab-span {white-space:pre} ul.ul1 {list-style-type: disc} ul.ul2 {list-style-type: square} ul.ul3 {list-style-type: hyphen} </style> <br /><div class="p1"><br /></div></div>Nawraj Lekhakhttp://www.blogger.com/profile/00225506272585891824noreply@blogger.com2tag:blogger.com,1999:blog-6880492769470667099.post-61253675192284420032017-08-01T19:54:00.000+05:302018-09-12T23:51:36.395+05:30Python OOP fundamentals<div dir="ltr" style="text-align: left;" trbidi="on"><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Print:</span></b></div><div class="p1"><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print("%s is %s years old" % (name, age))</span></div><div class="p1"><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style> </div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print('{0} is {1} years old'.format(name, age))</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">format in custom way:</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print("First: {foo}, Second: {bar}".format(bar=22.42,foo=41)) <span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># reuse single. used more than once</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print("More: {0:6.2f} or {0:6.3f}".format(5.1234))</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># ignore multiple. Extra parameters ignored.</span></div><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; min-height: 17.0px} </style> <br /><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print("More: {1:6.2f} or {1:6.3f}".format(12.345, 5.1234))</span></div><div class="p1"><br /></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Class name</span></b></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">1. private (_)</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">- begins with single underscore</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def _copy(list):</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">- means used in present module</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-tab-span"> </span>not available elsewhere</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-tab-span"> </span>module “import” ignored</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-tab-span"> </span>internal use only</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">2. Framework-reserved (_ _)</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">- Two or more</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>must start and end with _</span></div><div class="p1"><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; min-height: 17.0px} span.Apple-tab-span {white-space:pre} </style> </div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def __init__</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">pip = pip install packages</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Pypi = python package index</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">PEP : Python enhancement proposal</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def show():</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("\t***************")</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('\t* Hello World *')</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('\t***************')</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">show()</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">or</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">banner:</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def ShowStars(num):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>return "\t*" + ("*" * (num + 3))</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def Show(message):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>xx = len(message)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>stars = ShowStars(xx)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print(stars)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("\t* " + message + " *")</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print(stars)</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Show("This is a MESSAGE")</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Type change:</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">sNum = '20'</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print(type(sNum))</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">iNum = int(sNum)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print('*'*iNum)</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">comparison operators:</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">__gt__()</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">__lt__()</span></div><div class="p2"><br /></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">import builtins</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">help(builtins)</span></div><div class="p2"><br /></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">isFun = True</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">isTough = False</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">if isFun or isTough:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("one out of 2 ain't bad")</span></div><div class="p2"><br /></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">if not isFun:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("Practices makes it fun")</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">if not (isFun and isTough):</span></div><div class="p1"><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; min-height: 17.0px} </style> </div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp;&nbsp;</span>print("Learn C/C++")</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">sorting dict keys:</span></b></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def sortLogic(ref):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>return len(ref)</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">data = {"First":"John", \</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; </span>"Last": "Doe",<span class="Apple-converted-space">&nbsp; </span>\</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; </span>"Phone": "95496349",<span class="Apple-converted-space">&nbsp; </span>\</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; </span>"Email": "test@hotmail.com"}</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">zkeys = list(data.keys())</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print(zkeys)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">zkeys.sort(key=sortLogic)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print(zkeys)</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">for zkey in zkeys:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("%10s:[%-20s]" % (zkey, data[zkey]))</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><b>sorted:</b></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print(sorted(("Mr. Ed", "Mar Daisy", \</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>"Mr. T", "Dr. Who"))) # tuple</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print(sorted(["Mr. Ed", "Mar Daisy", \</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>"Mr. T", "Dr. Who"])) # list</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print(sorted({"Mr. Ed", "Mar Daisy", \</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>"Mr. T", "Dr. Who"}))<span class="Apple-converted-space">&nbsp; </span># set</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">print(sorted({4:"Mr. Ed", 2:"Mar Daisy", \</span></div><div class="p1"><style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Verdana; min-height: 17.0px} </style> </div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>3:"Mr. T", 1:"Dr. Who"}))<span class="Apple-converted-space">&nbsp; &nbsp; </span># Dict Keys<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">An object has two characteristics:</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">•<span style="white-space: pre;"> </span>attributes</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">•<span style="white-space: pre;"> </span>behavior</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Let's take an example:</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Parrot is an object,</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">•<span style="white-space: pre;"> </span>name, age, color are attributes</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">•<span style="white-space: pre;"> </span>singing, dancing are behavior</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">The concept of OOP in Python focuses on creating reusable code. This concept is also known as DRY (Don't Repeat Yourself).</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">In Python, the concept of OOP follows some basic principles:</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Inheritance<span style="white-space: pre;"> </span>A process of using details from a new class without modifying existing class.</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Encapsulation<span style="white-space: pre;"> </span>Hiding the private details of a class from other objects.</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"></span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">Polymorphism<span style="white-space: pre;"> </span>A concept of using common operation in different ways for different data input.</span><br /><div><br /></div><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># class defines methods and data attributes of particular object</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># The special __init__ method of class.Its job is to initialise or assign some values to its data attributes whenever we first create object.</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># attributes are data we can assign values to and which can be used later.</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># methods are used to perform operation on data attributes</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># class attributes can be used outside class</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"> <!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" DefPriority="99" LatentStyleCount="375"> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 9"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="header"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footer"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index heading"/> <w:LsdException Locked="false" Priority="35" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of figures"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope return"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="line number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="page number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of authorities"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="macro"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="toa heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 5"/> <w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Closing"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Signature"/> <w:LsdException Locked="false" Priority="1" SemiHidden="true" UnhideWhenUsed="true" Name="Default Paragraph Font"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Message Header"/> <w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Salutation"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Date"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Note Heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Block Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="FollowedHyperlink"/> <w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Document Map"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Plain Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="E-mail Signature"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Top of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Bottom of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal (Web)"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Acronym"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Cite"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Code"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Definition"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Keyboard"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Preformatted"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Sample"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Typewriter"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Variable"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Table"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation subject"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="No List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Contemporary"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Elegant"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Professional"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Balloon Text"/> <w:LsdException Locked="false" Priority="39" Name="Table Grid"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Theme"/> <w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> <w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/> <w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/> <w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/> <w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/> <w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/> <w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Mention"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Smart Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hashtag"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Unresolved Mention"/> </w:LatentStyles></xml><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-536870145 1107305727 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman",serif; mso-fareast-font-family:"Times New Roman";} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} </style></span></div></div>--&gt; <!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style><![endif]--> <!--StartFragment--><span style="color: #252830; font-family: &quot;arial&quot; , sans-serif; font-size: 12.0pt;">A class is a blueprint for the object.&nbsp;</span><!--EndFragment--><span style="background-color: white; color: #252830; font-family: Calibri, sans-serif; font-size: 11pt;">From class, we construct instances. An instance is a specific object created from a particular class.</span> <!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="&#45;-"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" DefPriority="99" LatentStyleCount="375"> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 9"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="header"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footer"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index heading"/> <w:LsdException Locked="false" Priority="35" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of figures"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope return"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="line number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="page number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of authorities"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="macro"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="toa heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 5"/> <w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Closing"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Signature"/> <w:LsdException Locked="false" Priority="1" SemiHidden="true" UnhideWhenUsed="true" Name="Default Paragraph Font"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Message Header"/> <w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Salutation"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Date"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Note Heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Block Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="FollowedHyperlink"/> <w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Document Map"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Plain Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="E-mail Signature"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Top of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Bottom of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal (Web)"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Acronym"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Cite"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Code"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Definition"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Keyboard"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Preformatted"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Sample"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Typewriter"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Variable"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Table"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation subject"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="No List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Contemporary"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Elegant"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Professional"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Balloon Text"/> <w:LsdException Locked="false" Priority="39" Name="Table Grid"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Theme"/> <w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> <w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/> <w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/> <w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/> <w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/> <w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/> <w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Mention"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Smart Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hashtag"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Unresolved Mention"/> </w:LatentStyles></xml><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-536870145 1107305727 0 0 415 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman",serif; mso-fareast-font-family:"Times New Roman";} p {mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman",serif; mso-fareast-font-family:"Times New Roman";} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} --></style><!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;} </style><![endif]--> <!--StartFragment--> <!--EndFragment--><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">class Employee:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>def __init__(self):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.firstname = 'nawraj'</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.lastname = 'Lekhak'</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def main():</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('This python programming is now starting')</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp; &nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">main()<span class="Apple-converted-space">&nbsp;</span></span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">when ever you define main it should be on level of class not within class because it is not class method and considered as main function.</span></div><div class="p2"><br /><br /></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">### create class attributes</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">class Person:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>'Base class of a person'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><i><span class="Apple-converted-space">&nbsp; </span># class attributes</i></span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>first_name = 'Nawraj'</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>last_name = 'lekhak'</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>age = 30</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def main():</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>#print the title of the program</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("\t *************Welcome to Employee Database ***********")</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print()</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># Print the class attributes values.</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("First name is:", Person.first_name)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("Last name is:", Person.last_name)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("Age:", Person.age)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print() ## to add additional line for seperation</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># Call the main method to start the program</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">main()</span></div><div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span><br /><h2 style="background: white; margin-bottom: 5.4pt; margin-left: 0cm; margin-right: 0cm; margin-top: 9.6pt;"><span style="color: #252830; font-family: &quot;arial&quot; , sans-serif; font-size: 23.0pt;">Object<o:p></o:p></span></h2><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"> <!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" DefPriority="99" LatentStyleCount="375"> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 9"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="header"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footer"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index heading"/> <w:LsdException Locked="false" Priority="35" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of figures"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope return"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="line number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="page number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of authorities"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="macro"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="toa heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 5"/> <w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Closing"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Signature"/> <w:LsdException Locked="false" Priority="1" SemiHidden="true" UnhideWhenUsed="true" Name="Default Paragraph Font"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Message Header"/> <w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Salutation"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Date"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Note Heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Block Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="FollowedHyperlink"/> <w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Document Map"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Plain Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="E-mail Signature"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Top of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Bottom of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal (Web)"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Acronym"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Cite"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Code"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Definition"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Keyboard"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Preformatted"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Sample"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Typewriter"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Variable"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Table"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation subject"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="No List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Contemporary"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Elegant"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Professional"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Balloon Text"/> <w:LsdException Locked="false" Priority="39" Name="Table Grid"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Theme"/> <w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> <w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/> <w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/> <w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/> <w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/> <w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/> <w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Mention"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Smart Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hashtag"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Unresolved Mention"/> </w:LatentStyles></xml><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-536870145 1107305727 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman",serif; mso-fareast-font-family:"Times New Roman";} h2 {mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"Heading 2 Char"; mso-style-next:Normal; margin-top:2.0pt; margin-right:0cm; margin-bottom:0cm; margin-left:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan lines-together; page-break-after:avoid; mso-outline-level:2; font-size:13.0pt; font-family:"Calibri Light",sans-serif; mso-ascii-font-family:"Calibri Light"; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:"Calibri Light"; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#2F5496; mso-themecolor:accent1; mso-themeshade:191; font-weight:normal;} span.Heading2Char {mso-style-name:"Heading 2 Char"; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 2"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:13.0pt; font-family:"Calibri Light",sans-serif; mso-ascii-font-family:"Calibri Light"; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:"Calibri Light"; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#2F5496; mso-themecolor:accent1; mso-themeshade:191;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} </style></span></div>--&gt; <!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style><![endif]--> <!--StartFragment--> <span style="color: #252830; font-family: &quot;arial&quot; , sans-serif; font-size: 12.0pt;">An object (instance) is an instantiation of a class. When class is defined, only the description for the object is defined. Therefore, no memory or storage is allocated</span><!--EndFragment--> <div class="p2"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span><br /><h2 style="background: white; margin-bottom: 5.4pt; margin-left: 0cm; margin-right: 0cm; margin-top: 9.6pt;"><span style="color: #252830; font-family: &quot;arial&quot; , sans-serif; font-size: 23.0pt;">Methods<o:p></o:p></span></h2><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"> <!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" DefPriority="99" LatentStyleCount="375"> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 9"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="header"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footer"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index heading"/> <w:LsdException Locked="false" Priority="35" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of figures"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope return"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="line number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="page number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of authorities"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="macro"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="toa heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 5"/> <w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Closing"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Signature"/> <w:LsdException Locked="false" Priority="1" SemiHidden="true" UnhideWhenUsed="true" Name="Default Paragraph Font"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Message Header"/> <w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Salutation"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Date"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Note Heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Block Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="FollowedHyperlink"/> <w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Document Map"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Plain Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="E-mail Signature"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Top of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Bottom of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal (Web)"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Acronym"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Cite"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Code"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Definition"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Keyboard"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Preformatted"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Sample"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Typewriter"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Variable"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Table"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation subject"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="No List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Contemporary"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Elegant"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Professional"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Balloon Text"/> <w:LsdException Locked="false" Priority="39" Name="Table Grid"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Theme"/> <w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> <w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/> <w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/> <w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/> <w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/> <w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/> <w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Mention"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Smart Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hashtag"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Unresolved Mention"/> </w:LatentStyles></xml><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-536870145 1107305727 0 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman",serif; mso-fareast-font-family:"Times New Roman";} h2 {mso-style-priority:9; mso-style-qformat:yes; mso-style-link:"Heading 2 Char"; mso-style-next:Normal; margin-top:2.0pt; margin-right:0cm; margin-bottom:0cm; margin-left:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan lines-together; page-break-after:avoid; mso-outline-level:2; font-size:13.0pt; font-family:"Calibri Light",sans-serif; mso-ascii-font-family:"Calibri Light"; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:"Calibri Light"; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#2F5496; mso-themecolor:accent1; mso-themeshade:191; font-weight:normal;} span.Heading2Char {mso-style-name:"Heading 2 Char"; mso-style-priority:9; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:"Heading 2"; mso-ansi-font-size:13.0pt; mso-bidi-font-size:13.0pt; font-family:"Calibri Light",sans-serif; mso-ascii-font-family:"Calibri Light"; mso-ascii-theme-font:major-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:major-fareast; mso-hansi-font-family:"Calibri Light"; mso-hansi-theme-font:major-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:major-bidi; color:#2F5496; mso-themecolor:accent1; mso-themeshade:191;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} </style></span></div>--&gt; <!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style><![endif]--> <!--StartFragment--> <span style="color: #252830; font-family: &quot;arial&quot; , sans-serif; font-size: 12.0pt;">Methods are functions defined inside the body of a class. They are used to define the behaviours of an object</span><!--EndFragment--> <span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><br /></span><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">##create object based on Employee class</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">class Employee:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>'Base class of a Employee'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># set default constructor</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp; ## instance attributes</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>def __init__(self):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.first_name<span class="Apple-converted-space">&nbsp; </span>= "Nawraj" # to reference data attributes</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.last_name = "Lekhak"</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.uid = '321'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp; &nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def main():</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># create object based on Employee class</span><br /><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span><span style="background-color: white; color: #4c886b; font-family: &quot;monaco&quot;; font-size: 9.5pt;"># instantiate the Employee class</span><br /><!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-IN</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="false" DefSemiHidden="false" DefQFormat="false" DefPriority="99" LatentStyleCount="375"> <w:LsdException Locked="false" Priority="0" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index 9"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" Name="toc 9"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="header"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footer"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="index heading"/> <w:LsdException Locked="false" Priority="35" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="caption"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of figures"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="envelope return"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="footnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="line number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="page number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote reference"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="endnote text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="table of authorities"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="macro"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="toa heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Bullet 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Number 5"/> <w:LsdException Locked="false" Priority="10" QFormat="true" Name="Title"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Closing"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Signature"/> <w:LsdException Locked="false" Priority="1" SemiHidden="true" UnhideWhenUsed="true" Name="Default Paragraph Font"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="List Continue 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Message Header"/> <w:LsdException Locked="false" Priority="11" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Salutation"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Date"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text First Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Note Heading"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Body Text Indent 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Block Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="FollowedHyperlink"/> <w:LsdException Locked="false" Priority="22" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Document Map"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Plain Text"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="E-mail Signature"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Top of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Bottom of Form"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal (Web)"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Acronym"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Address"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Cite"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Code"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Definition"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Keyboard"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Preformatted"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Sample"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Typewriter"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="HTML Variable"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Normal Table"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="annotation subject"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="No List"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Outline List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Simple 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Classic 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Colorful 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Columns 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Grid 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 4"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 5"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 7"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table List 8"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table 3D effects 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Contemporary"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Elegant"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Professional"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Subtle 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 1"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 2"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Web 3"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Balloon Text"/> <w:LsdException Locked="false" Priority="39" Name="Table Grid"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Table Theme"/> <w:LsdException Locked="false" SemiHidden="true" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" Name="Light List"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" SemiHidden="true" Name="Revision"/> <w:LsdException Locked="false" Priority="34" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" SemiHidden="true" UnhideWhenUsed="true" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" SemiHidden="true" UnhideWhenUsed="true" QFormat="true" Name="TOC Heading"/> <w:LsdException Locked="false" Priority="41" Name="Plain Table 1"/> <w:LsdException Locked="false" Priority="42" Name="Plain Table 2"/> <w:LsdException Locked="false" Priority="43" Name="Plain Table 3"/> <w:LsdException Locked="false" Priority="44" Name="Plain Table 4"/> <w:LsdException Locked="false" Priority="45" Name="Plain Table 5"/> <w:LsdException Locked="false" Priority="40" Name="Grid Table Light"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="Grid Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="Grid Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="Grid Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="Grid Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="Grid Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="Grid Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="Grid Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 1"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 1"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 1"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 1"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 1"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 1"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 2"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 2"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 2"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 2"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 2"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 2"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 3"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 3"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 3"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 3"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 3"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 3"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 4"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 4"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 4"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 4"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 4"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 4"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 5"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 5"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 5"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 5"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 5"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 5"/> <w:LsdException Locked="false" Priority="46" Name="List Table 1 Light Accent 6"/> <w:LsdException Locked="false" Priority="47" Name="List Table 2 Accent 6"/> <w:LsdException Locked="false" Priority="48" Name="List Table 3 Accent 6"/> <w:LsdException Locked="false" Priority="49" Name="List Table 4 Accent 6"/> <w:LsdException Locked="false" Priority="50" Name="List Table 5 Dark Accent 6"/> <w:LsdException Locked="false" Priority="51" Name="List Table 6 Colorful Accent 6"/> <w:LsdException Locked="false" Priority="52" Name="List Table 7 Colorful Accent 6"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Mention"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Smart Hyperlink"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Hashtag"/> <w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed="true" Name="Unresolved Mention"/> </w:LatentStyles></xml><![endif]--><style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-536870145 1107305727 0 0 415 0;} @font-face {font-family:Monaco; panose-1:0 0 0 0 0 0 0 0 0 0; mso-font-charset:77; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:-1610611969 1342192123 0 0 407 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman",serif; mso-fareast-font-family:"Times New Roman";} span.acecomment {mso-style-name:ace_comment; mso-style-unhide:no;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} </style></div>--&gt; <!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style><![endif]--> <!--StartFragment--> <div class="MsoNormal" style="background: white; line-height: 12.0pt;"><span style="font-family: &quot;monaco&quot;; font-size: 9.5pt;"><o:p></o:p></span></div><!--EndFragment--><br /><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_01 = Employee() ## here employee_01 is obj of class Employee</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_02 = Employee()</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_03 = Employee()</span></div><div class="p2"><br /></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">##Obtain object attributes</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">class Employee:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>'Base class for our Employee'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># set default constructor, instance attributes</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>def __init__(self):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.first_name<span class="Apple-converted-space">&nbsp; </span>= "Nawraj" # to reference data attributes</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.last_name = "Lekhak"</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.uid = '321'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp; &nbsp;</span><br /><span style="color: #4c886b; font-family: &quot;monaco&quot;; font-size: 9.5pt;">&nbsp;# instance method</span><span style="font-family: &quot;trebuchet ms&quot; , sans-serif; font-size: 12pt;">&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>def get_first_name(self):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>return self.first_name</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp; &nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>def get_last_name(self):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>return self.last_name</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp; &nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>def get_uid(self):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>return self.uid</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp; &nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def main():</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># create object based on Employee class</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_01 = Employee()</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>## Access and print the first last_name. Access class attributes</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('First name:', employee_01.get_first_name())</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('Last name:', employee_01.get_last_name())</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('Uid:', employee_01.get_uid())</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"># call main method</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">main()</span></div><div class="p2"><br /></div><div class="p1"><b><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">##Changing object attribute values</span></b></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">class Employees:</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>'Base class for our Employees'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># set default constructor when new objects are created</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>def __init__(self):</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.first_name<span class="Apple-converted-space">&nbsp; </span>= "n/a" # to reference data attributes</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.last_name = "n/a"</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; &nbsp; </span>self.uid = 'n/a'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp; &nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;">def main():</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># create object based on Employees class</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_01 = Employees()</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('First name:', employee_01.first_name)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('Last name:', employee_01.last_name)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print('Uid:', employee_01.uid)</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print()</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># Let's modify this object attribute values</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_01.first_name = 'Nawraj'</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_01.last_name = 'Lekhak'</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>employee_01.uid = '388921'</span></div><div class="p2"><span class="Apple-converted-space" style="font-family: &quot;trebuchet ms&quot; , sans-serif;">&nbsp;&nbsp;</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span># Print new assigned values</span></div><div class="p1"><span style="font-family: &quot;trebuchet ms&quot; , sans-serif;"><span class="Apple-converted-space">&nbsp; </span>print("New Values:")</span></div><div class="p1"><