Hi, in this video clip, we are studying "Augmented Assignments" and "Range function" in more detail. Now first, let me introduce augmented assignment. Augumented assignment simplifies your coding. Simply it simplifies your coding. So let me show you how does it simplifies. For example, previously we typed "a = a + 2". It means that there is initial value "a" you are adding "2" and then the added new value is updated to "a" variable. But how can you simplify this formula using augmented assignments? This one, "a+=2". It means that this one functions exactly the same as in the last column, "a =a +2". So augumented assignment can be applied to four calculations: minus, multiplied by, squared, divided by, floor division, remainder. Those are the augumented assignments that simplify your coding process. But before proceeding, let me show you another case markdown. So, by clicking this one. In this case, it is a figure. Figure information is inserted in the subdirectory "img". So, if you go back, here's "Coursera". In the "Coursera", 'img" subdirectory. Within the subdirectory, this is the PNG file that appears here. And it is alternative naming when the image does appear. And this width is used here to resize the figure. But basically, here, it is not markdown language. It is HTML markup language, right? So, HTML markup language can be used. And the above line is the markdown language. So let me execute this one, then it appears like this. So the "total" variable is assigned with zero, initialized by zero. And here is "for loop". And range "10" means that how many numbers will be contained, created by this range function. Actually, the number is ten, from zero to nine. Right? Ten is not inclusive. So then how many numbers are printed? From zero to nine and they are added. Total "i" from zero to nine is added. So if I execute this one from "0, 2,..., 9" and 45 total number is printed. If you want to "45" shown in next line, what should I do? Simply add print empty and then execute. Oh, vertically printed, vertically. But it is not what I wanted. In that case, a little bit, this one, yeah. This is what I expected to get. And we got what we wanted. And another thing I need to explain is that, instead of this one, we can use this one also [typing]. Right? Instead of augmented assignment, we can use this one. And execute this one. Then the same outcome. But rather than this one, using the augmented assignment is simple, simpler than before. And the outcome is the same. And why if we use "sum" instead of total? The sum is actually built-in function. If you put something in sum, actually it calculated aggregated number. For example, let's insert another cell and test whether, how sum works. Sum it is a built-in function and we are inserting a list with two numbers, "23 and 17". We are adding two numbers in a list. Then the addition must be "40", and we got "40". So sum is a built-in function, adding the numbers, all the numbers in a list. So it is built-in function. But what about you use, instead of total, sum? Then what happens? Is it working or not working? Because you are using the name of a built-in function, what will happen? How do you think? What is your guess? It works or not works. See, it works perfectly as before. Then what is the cost you pay for using built-in function name as a variable name that you created? It is shadowing a built-in function. It means that you cannot use any more sum built-in function as a built-in function in your coding. So don't use the name of built-in function as a variable name. That is [typing] a kind of a common rule of thumb you need to follow. So don't use a built-in function name as your own variable name. Now let me introduce a kind of a loop using augmented assignment. Total number. Grades actually it is a list contains (numbers). How many numbers in it? Well, about 10, right? Ten numbers. And you are aggregating the numbers in the list. And then number of students, and then you are calculating. Print and using the print function you are printing average, an average number. So let's execute that. Then what happens? Well, the "Class average is 81.7". Ah, this print function. Two formatted strings. Printing, printing the calculated average. But in the second formated string, the formatted string is simply called "f-string" because always "f" is inserted, "f" formatted. Reduced name of formatted is "f" "f string". So in "f string", you can, so in "f string" you can insert formula, not just calculating numbers. If you put this one, the same number is calculated. And also in formatted string, you can use, you can specify format of that object. So dot after colon, you are inserting format of the parameter ".2" means that ".2f", "f" means that here float and two means that two digits. Two digits after the decimal point. So "81.70" is printed. What about we changed this into three?, Then, "81.700". Surely, we can add formats also above in formatted string. You can add any format. So "81.7" after colon, you can add format parameters. Later I will probably have a chance to explain in more detail the use of parameters in formating string. Now, let me explain a built-in function, "range" again. Range is, as I explained before, it is lazy evaluation. Lazy means that delay evalution . An object is evaluated when
it is needed or on-demand. At object is evaluated on demand, not when it is created. An the example of lazy evaluation is range function. Later some time, someday you will study generator, the concept of generator. You are making a kind of formula. But based on the formula, when you need real data, actually an object with specific numbers is created. So, the generator concept you will later study. But range function it is not a case of a generator. But in terms of lazy evaluation, both are the same. Well, let me give you a specific case of range function. Starting value is "10" ending number is "-10" and "-2" is step. Step. In range function, if you do not specify the step value, it is "+1". So, this is a range function with three parameters values. So, let's execute first, and then what happens? So, if you simply print that object "k" which is the range function with three parameters, those three parameters. Then actually, what is returned? Not specific numbers! That object information is provide here. How can you evaluate, how can you get evaluated numbers? So, there are a couple of ways. One is to use the list function. By containing that range object within a list function, actually, the real sequence of numbers is printed from "10". The step is "-2". So, number two is subtracted until minus eight because this is the last number. Last number is not used in range function. So, another way of creating the list of numbers is using for loop. From "k" range function, you are taking out each component, each item. From number "10" to "-8". So, this is a way of demanding the numbers. So, in this case, you need not a range object. You need numbers created by that range object. By using list functional for loop, you can get created items of a list. So, there are three ways of using the range function. One argument version. I already have shown you many times. Two arguments version. If two numbers are in the parenthesis of a range function, the first number is starting number, the second number is ending number. So what will be printed? From "7 to 19" will be printed horizontally because you are using "end". But at this time, you are inserting a comma. So, each number will be separated by comma. Three arguments case. Starting number "10", ending number "20", the step is "3". So "10, 13, 16, 19" will be printed. Right? In this case, starting number is "15", ending number is "0" and step is "-2", then two numbers. The number will decrease, sequential number decreases by two. So, let me execute this one. From 7 to 19 and separated by comma because we inserted comma here. And as I explained before, the starting number is "10" and increases by "3". What about we change "3" into "2"? Then "20" will be printed or not? Not printed, the ending number will be "18". Right? "10, 12, 14, 16, 18". So, the ending number is not inclusive in range function. In Python in most cases, the ending number is not inclusive. And, in the last case, it is decreasing from "15" by "2" and ending number is "1". Before finishing this video clip, another review question. A range function creates a sequence of integers on-demand, on-demand. I will like to emphasize this one. So, this way of executing, creating a list of numbers is calling lazy evaluation.