 Me and my colleague Abhishek will walk through your Python and then in the later half Django which is a web framework based on Python. So starting with the head points which we have covered in Python is history, assignment and name conventions, basic data types, sequences which includes lists, tuples and strings, some mutability concepts, modules and in the last errors and exceptions. The brief history of Python is that it's been invented in the Netherlands early 90s by Udo Wen Rossum. It's an open source language. Earlier it was sort of just a scripted language but it's much more than a scripted language. We can use this as a system language too. It is an interpreted, object-oriented and functional language. So running Python, first of all we can download from this URL, s2dpython, org.download. The typical Python implementations offer both an interpreter and compiler. So in interpreter mode in Ubuntu, Python is by default installed. So if you type at the command drop Python it will go into the interpreter mode. At the Unix 2 in the interpreter mode the prompt starts with 3. So in the interpreted mode when you are in the Python interpreter mode if you type 3 plus 3 it will interpret 3 plus 3, not compiled and give you the executed value that is 6. To exit from the Python interpreter in Unix we type control d and in Windows if you are running in the interpreted mode in Python in Windows we type control z to the center. Some of the examples in interpreter mode includes if we type such as interpreter mode we can define a function def qubex which returns and there is a default function map qub which returns the qub value. Here 1, 2, 3, 4 is the parsed list. So it will return qub of all this list. So it will return 1, 8, 27, 64. Running programs on Ubuntu. Python programs ends with an extension .py file. So we, Python files say it's a .py file and calling Python program by the Python interpreter we type Python if it's a file, suppose intent.py. So we can call Python intent.py. For making a Python file directly executable we have to include these line in the first line just as this. Pound slash dollar user bin environment Python. And then we have to make the file executable. So in Linux or Ubuntu we do that with sudo change mode plus x which is executable mode intent.py file. And then we can invoke the file dot backslash intent.py. So now we don't have to use the Python intent.py we can directly execute it slash dot slash intent.py. The basics. Basics data types includes as in all other languages which is a long integer. Here it is a complex, complex numbers and floats x which is a simple complex number 3.456. These basic data types are immutable in strings. We can define strings with double quotes or single quotes to specify with string double quotes ABC is equal to single quotes ABC. So both are equal. Unmatch can occur within the string which means we can define a string max which includes an epistopias. So we can include double quotes. We can also use triple quotes for a multiple line strings or strings that contain both single quotes and inside of them. So to define a we have to include it in the triple quotes string. So A slash B double quotes C. It's a string. It will be a string A slash B double quotes C. Why spaces is meaningful in Python such as specially indentation and placement of new design. In Python the scopes are defined by indentations. There is no opening or closing places which says there is a start of the scope or end of the scope. So in Python the scopes are defined with consistent spaces. Use a new line to end a line of code. Use black slice and go to this. So no braces to mark blocks of code. Use consistent indentation in seed. First line with indentation is out of the block and if we include more indentation in the next line it will be a nested block. Typically colons also define block in many constructs. Example functions definitions if then clause for loops. So if we have to define a for or a function we have to start with a scope which is defined by a colon. So for colon in Python comments starts with a power sign and if we start with this rest of the line is ignored. It's interpreted as a comment. We can include a comment as a document string for example in the developer the first line of new function or a class you define. Such as here we have defined a definition packed function. So this is a multiple line string which we call as a doc string for the function which says what this function returns or what it does. So it's basically a comment for this function which says what this function was. In Python binding a variable means setting a name to hold a reference to some object which means assignment creates only references not copies. In pythons do not have an instinctive type of object subtypes. So Python determines the type of the reference automatically based on what is assigned to it. So if you define x equals to 3 it's automatically interprets as an integer. If we say x equals to in code string so it's the object of type string. It will interpret that as the object type string. Assignments is as usual you can create an assignment first up your left side of is the name which holds the value 3. And the references are collected by the automatic garbage collection of Python when it goes out of scope. Naming rules which are typically very much similar to other languages. Names and case are case sensitive and cannot start with a number. They can only contain letters, numbers and underscores. For example bob, bob, underscore, bob, underscore, two, bob. So these are all valid names and there are some reservoirs we cannot use as a variable names. Examples are and, as heard, gray, class, continue, etc. Assignment, in Python you can assign multiple names at the same time. So we say x, y equals to 2, 3. So it says gives x to value 2 and y to value 3. And which makes it easy to swap values. So we first define x, y equals to 2, 3 and then we have to swap the values x, y equals to. It will then assign 3 to x and y to 2. And assignment can be changed. So in a single line we can assign a equal to b equal to x which is equals to 2. And accessing a name before it's been properly created by placing it on the left side or assignment raises an error. So if we have not defined y to anything and we, in the interpreted mode, we type y. It will return an error which says y is not defined. But if we define y is equals to 3 and then prompt y, it will return 3. Control flow includes a while statement, false statements, if statements. Here it is an example for a while statement. It starts with a count, then while count lies in. So it will print the count, increment the count up to the count value of which is less than 9. And prints the count in each loop. For statements we can define words as a cat which is a list of strings. Cat, window, differentiate. And if we loop in words it will print in each loop cat, window, differentiate. Python, the if statement we have defined x is equals to which takes inputs from the command line. Then loops checks if statement, if x is equals to 3. It's a typical if statement example. Here the else, else is defined as EL if, not else space if. Python there is a default function range. So if we pass some value in the range. So it will loop for i in range 5. It will loop up to starting with 0 up to a n minus 1. So here it will print 0 to 4. There are some pass, break, continue statements. So for letter in python here we have checked if the letter is equals to equal to h. So it will loop through all through python. The initial letters first it will take value letter is equals to 5 then y. And if that value becomes h we are breaking out of the loop. So it will only print up to pyp and then when letter is equals to h it will break out of the loop. Functions. So functions are defined with a keyword df and the function name will be anything, valid function names. So here we have defined a function fib n which writes humanized series. So definition fib n series up to n. So first we have initialize a and b equal to 0 to 1. Then loop to n while a is less than n print a. Here typically a comma b will, as we have seen earlier a will be assigned each and in a loop. a will be assigned b and b will be assigned to a plus b. And it will print the values. So if we call fib with a value 2000 it will start from 0 then print 1, 2, 3 which is a humanized series. Functions can be called using keyword arguments of the form where k log is equals to value. For instance the following function we have defined a function definition parrot which takes argument as voltage and state we have defined state is equals to a step which is a default value for state a step. Action is equals to we have defined a default value action to whom type we have defined or equal to norwegian. And then we have print something by calling this functions. So this definition parrot accepts one required argument which is a voltage and three optional arguments state, action and type. So this parrot functions can be called in any of the following ways parrot 1000. So it will not take as a k log value but it will take positional argument which is the first one. So it will take thousand value of the voltage. So voltage will be defined as 1000 then it will print the statements and take all the value state as a step which is a default values for all these. We can also define parrot voltage is equals to 1000 so it's a keyword argument. We have passing calling the function parrot voltage with a voltage value 2000. We can also call parrot voltage is equals to 10000 action is equals to whom. So here we are calling the parrot as a two keyword arguments where voltage is equals to 10000 and action is equals to within the string whom. We can also add here the position of the arguments doesn't matter if we are calling it we can also call action is equals to whom or comma voltage is equals to here. So it's same as first one voltage is equals to 10000 action is equals to whom. So this one and the previous one are the same both will be the same function and return the same value. We can also call without and keyword arguments as a positional value. So we can call parrot where we are passing a million a barret of life comma jump here the value of voltage will be a million state will take a barret of life and type will be again a jump again. We can call as a one positional argument and one keyword arguments. So here we have positional argument is for voltage and keyword argument is the state we are passing pushing up the dice comparison between Java and versus Python. All variable names along with the types must be explicitly declared in Java. We have to first declare then we have to define the values in Python. You never declare anything. You just say why is it goes to three? Why is it goes to not why is it goes to integer? We have not not have to declare anything integer string. So it takes as it is defined. So if we define why is it goes to three? So why will we assign a value to and type will be an integer in Java. Container object example vector and error list holds objects of generic type object but cannot hold primitive site such as integer. But in Python container objects as a list and recognition hold objects of any type including lists when you list. It can type of mixed values. It can contain a list a string or list within a list and when you retrieve an object from a container using index values. So it remembers this type. So we have to not cast it again to the string. So if we say print hello world in Java for printing a hello world we have to define a class of public public's class and public static board string arguments. Then we have to print out system dot type to print a single hello world. But in Python in the intermittent mode we have to play if we have to print a hello world. We have just defined print hello world and it will output the string hello world in Java. Each top-level public class must be defined in its own file. So if your application has 15 such classes it has 15 files. But multiple classes can be defined in a single file in Python. So if your application contains 15 classes that entire application could be stored in a single file. Sequence types. Python sequence types includes tuples, lists and strings. But the example of tuple is here which is in brackets john comma 32 and then a list cmsc. So in a simple it's a simple immutable order sequence of items. Items can be of mixed types including collection types. So here the collection type is a list again list. Strings. Strings we can define in the double quotes which is here we have defined string as john smith. So strings are immutable objects in Python. Conceptually very like like a tuple. And list we can again define the list here it is defined. So list one two is again contain a mixed type integers john and the last one is again a tuple. So lists are mutable order sequence of items of mixed types. All three sequences types such as tuples strings and lists share much of the same syntax and functionality. The only difference is that tuples and strings are immutable whereas list is mutable. Next we will show some operations on this sequences. So the operation shown in the sections can be applied to all sequence type. Most examples will show the operation performed on one. So we can define tuples using parenthesis and commas. So here we have defined a tuple tu with parenthesis which contains items of first one is integer 23. Then string abc float then a tuple then a string df. We can define a list using a square brackets and commas. So list is square bracket string abc then integer float then again integer. As stated earlier defined strings we can define string as using single quotes or double quotes. Operations on sequences are we can access individual members of a tuple list or string using square bracket as a notation. All of the sequences are based on zero. All of tuples strings and list all start at the zero index. So we define tuple bracket 23 abc and if we say type tuple 1. The second item in the tuple will be printed. The first one is zero which is at 23 and the second one is abc. So its index is one. Same is true for list and string. We can define positive and negative indexes. If we define a positive index it starts from left to right. And for the negative index it starts from right to left. There is a concept of slicing in python. So we define tuple 23 abc. So slicing retain a copy of the container with a subset of the original members. So start copying at the first index and stop copying before second. So we can define. So t slice from the first and end before fourth. Same is true for negative index counting from the end. We can also omit the first index to make copy starting from the beginning of the container. So if we omit the first index it will start copying from the first one. Similarly we can omit the second index to make start copying at first index and going to the end. If we omit both first and last index it will copy the whole sequences. Note the differences between these two lines of mutable sequences. Since list is a mutable sequence. So if there is two lists we have defined L1 and L2. And we specify L2 equal to L1 to both refer to one changing one of export. If we define L2 equals to L1. Here it is an independent copies of two references. There is a Boolean operator for checking in sequences. So Boolean test whether value is inside a container or not. So we define t equals to list 1, 2, 3, 4. So we can check if 3 belongs in list t. So if we type 3 in t it will return false because 3 is not in the list. If we type 4 in t it's a Boolean test and it will return a true. And 4 not in t because 4 belongs to 4 it will return false. Save is true for strings. So for strings test of substrings a is equals to a string a, b, c. So we can check for substring. If cd will in a it will say return true. Ac in a because ac is not a substring of a, b, c, d. So it will return a false. The plus operator in sequences the plus operator produces a new people list or string whose values is a concatenation of the arguments. So if we use operator plus between two tuples 1, 2, 3 and the second tuple is 4, 5, 6. So it will return a new tuple which is a concatenation of both the tuples. So it will return 1, 2, 3, 4, 5, 6. Same is true for list and for strings. Star operator the star operator produces a new people list or string that repeats the original content. So if we say 1, 2, tuples star 3. So it will return tuple which repeats the original content. So 1, 2, 3, comma 1, 2, 3, then again 1, 2, 3. Similar is true for list and strings. So if we say hello string star 3. So we return a new string hello repeating a sequence of three hello. Mutability tuples versus list. List as we have said list are mutable but tuples are not mutable. If we define a list which is a list of items a, b, c and we say it goes to 45 because list is mutable. So the first second item of the list will be changed to 23. We again print li to the 23 is replaced with a new value 45 because list are mutable. We can change list in place. Name li still points to the same memory reference where we are done. So it's a reference to the same memory reference. But tuples are immutable. So if we say t define t and again try to change the any index position of tuple. If we say t2 is goes to it will the python will return error because object doesn't support item assignment because list is immutable. It cannot change the value of the tuple in place. So you cannot change a tuple. You can make a fresh copy and assign its reference to a previously used name. The immutability of tuples means they are faster than lists. There are some operations which are applicable to list only. So there is an operation append. So we define list over and then use an append operations which takes arguments. So the new list will be it will append a at the last index. We can insert takes the index position and the value of the tuples. So li insert to one so it will the i will be inserted in third item of the list. A new list will return where one and third item is now i. The extend method versus the plus operator. The plus operator creates a fresh list with a new memory reference whereas extend operates on list in place. So if we define a list for li.extent987 it will replace the list. It will not create a new copy of the list. So extend and append are potentially confusing and extend takes a list as an argument and append takes a singleton as an argument. So if we say li.append a list so a whole list will be appended. So the list was defined as this and we have used the append function. We have passed the argument as a list 10, 11, 12. So the new list will be the last position will be indexes with 10, 11 and 12. There are some more operations which are applicable on lists only such as index, count, reverse, short. So li.index will return the index position of the b or first occurrence. So li.count will return the number of occurrences of b. So for example in this list a, b, c and b li.index will return 1 because the first b occurs at the position 1 li.count it will return the number of occurrences of b. So it will return 2 and we can use remove. So if we use li.removeb so it will remove the first occurrence of the b. So the first occurrence of b was index 1 so that will be removed and a new list will be again a, c and b. We can reverse the list by using a reverse function. So li.reverse reverse the list in place. So the list will be now 8, 6, 2, 5. We can short in place. So the shorting will return 2, 5, 6, 8 which is the short order of the list. We can also pass a function which is a user defined function for shorting. There are some tuple details. The comma is the tuple creator operator and not the parenthesis. So if we say 1 comma so it will be a tuple and not an integer 1. So the parenthesis are only used for clarity. If we forget the using the comma and only use the parenthesis it will only return integer d 1 and not the tuple. We can also define empty tuple which is only the parenthesis or call a tuple function empty. In summary, tuple list is lower but more powerful than tuples. List can be modified and they have lots of handy operations and methods. Tuples are mutable and we have fewer operations. We can convert between tuples and list using list and tuple function. So if we have to convert a tuple to list we can pass the tuple in the list function. It will return the list of tuples and conversely we can change tuple list to tuple by using a tuple function. Next to modules. Up till now we have all examples has been defined as interpreted mode. So in python what is the module? A module is a file containing python definition and statements. The file name is the module name with the suffix. Extension is .py. Within the module the module name has a string. For instance use your favorite text editor create a file called feebo.py in the current directory with the following contents. A module feebo.py contains two definitions. One is for returning series of fibrillation up to n. Second one is again the repetition of that. But we can call fib n and fib to n. So this is a module containing two definition functions. Def fib n and def fib to n. Now in the interpreter mode if we have to call the module we have to first import that module. So we have to type import feebo. This does not enter the names of the function defined to feebo directly. It only creates the current symbol and module name feebo there. Using the module name you can access the function. So now we have imported the feebo in a symbol name feebo. And now using that symbol name feebo we can call the individual functions of that module. So we have to call fib n. We can call feebo.fib with argument 1000. Similarly we can call the second function feebo.fib to with argument 100. The module search path. When a module name create list.py is imported the interpreter starts searches from built-in module with that name. If not found it then searches for a file name create list.py in a list of directories given by the variable system paths. And system path is analyzed from the locations. First one is the directory containing the script which is the create list or the current write where no file is specified. And there is a python path which is same as cell variable path. Error handling in pythons. Some errors are most common is syntax error. So syntax error which is also called passing errors are perhaps the most common kind of complainment but while you are still learning python. So here we have just in the interpreter we have type wild proof print hello world. So it will return a syntax error with statement that syntax error invalid syntax. Here the parser repeats the position error is caused by or at least detected at the token preceding the arrow. So here the error will be before the arrow. Since a colon is missing before it file name and printed you know while in case of input. There are some exceptions. So even if a statement or expression is syntactically correct it will may cause an error with an attempt to made it executed such as it is called exceptions. Here we have tried to enter the value 10 in 2 but divided by 0. So it will cause an exception error because it's a division by 0. Secondly we type 4 plus spam into 3. So it's again exception where spam is not defined and we cannot concatenate integer to string. So here we have tried to concatenate or add string plus 2. So it will return an exception that integer cannot be converted to the string implicitly. Python handling exceptions. So it is possible to write programs that handle selected exceptions in which here we have defined a loop of wild proof. And in the try and accept block we have try x equals to taking a input value from the command line. And in the accept block we have said that it's a value error. Try again. So handling exception starts the try statement works as follows. First the try clause the statement between the try and accept verse is executed. If no exception occurs the accept clause is skipped and execution of the try statement is finished. If an exception occurs during execution of the try clause the rest of this clause is skipped. Then if it's type matches the exception named after the accept keyword the accept clause is executed. And then execution continues after the try statement. If an exception occurs which does not match the exception named in the accept clause. Here the name of the exception we have only tried to cast the value error. So if there is no value error it will then go to the outer try statements. And in the outer try statement if there are no handle found it will handle exception and the execution stops. Enough to understand the code. So all we need to understand to know to understand the Python codes are mentioned here. So in Python indentation matters to code meaning. So block structure is indicated by indentation. First assignment to the variable creates it. So variables don't need to be declared. Python figures out the variables on its own. So assignment is by a single equal to and comparison is equal to equal to. For numbers plus minus multiply are expected. Special use of plus is for string concatenation and list concatenation. And formatting we can use percentage. Some of the logical operators are and or not, not symbols. And the basing printing command is sprint. So this is all for understanding the Python code. The next will be we shake will walk through the Django web framework which is based on Python. Thank you.