 So, welcome everyone. My name is Pushal Das. So, this is going to be a Python 3.101 workshop that means, okay that's my daughter. Her name is Pi from Python actually. We call her Pi. And so, I hope you don't mind her shouting a little bit. So, this workshop we are actually going through the basics of Python, the programming language itself and mostly looking at the changes in Python 3. So, before we start, I want to know how many of you already know Python in general. Can you please raise down? So, a lot. So, okay. And how many of you already using or already know about Python 3? Okay. So, a lot of new people here. So, you will see something, things which are already changed from 2.7 to 3.x release. And so, to do this workshop, you will need Python 3 on your computer. I hope you have installed, had it installed. Or I don't know what is the network condition here right now. So, that's the thing. So, a major announcement. I hope many of you already know about it. But there will be no Python 2.8. So, Python 2.7 is the last major release in the 2.x series. So, we will be releasing bug fixes, I think until 2020. I think that's the year. I may be wrong, but yeah. But there will be no Python 2.8 release. So, all the new features, all the new things in the language, it will be always on the Python 3 series. So, if you are starting up a new project, a new library, I think this is the best time to start directly working on Python 3 code base rather than working on Python 2. Because as I mentioned, there will be no more Python 2 incoming days. So, Python 3 is the future. There are already various projects and various libraries which moved into Python 3. From the last Fedora project release, Fedora 23, our distributions went by default with Python 3 only. That means if you install Fedora on a box, you will, or if you run it on a cloud, you will get only Python 3 in it. You have to install Python 2 if you want to use Python 2. I'll see if I can connect to network. Do you even know if it works still working? Oh, where is the mouse pointer? Yeah. So, for the people who are new to Python here, I know at least one person who came to me and for the other people who are just starting up with Python, this is a book which I wrote and it's actually, we still update it regularly. It's called Python for you and me. It's completely on, as you can see, the source is on GitHub. It's rendered in read.docs. So, if you have network, please open it up. So, we'll actually follow this book to quickly go through to the language parts so that if you are new to the language, you'll understand how this whole Python thing works. And in between, I'll keep talking about the new things or the things which changed between Python 2 or Python 3. Is it okay? Can anyone actually open that link? I don't know. I don't have network. So, I'll open it up locally. So, see if you can open it up. Okay. So, and remember that as I said that this book is on GitHub. So, if you see any typing mistakes, which is, must be there are a lot of them. Or if you want to add a new chapter, you want to work on it, feel free to send a pool request so that, you know, you can help the rest of the people. So, give me a second and I'll open up some local things. So, yes, there is one. Okay. So, there is one called a password for Cecilia keys for Cecilia. Is this working? Yes. Okay. The other one, even that is also not working for me. So, I guess that one should be connected to it. Can you help her a little bit on that computer? No, no, no. This one, this one. This one. Is this just for Cecilia? Yeah, I did that. And it did working. See, you'll have to go to for Cecilia Pauling. Yeah. This is actually, this is for the speakers. Yeah, because otherwise. Okay. So, to start Python 3, if you are new to Python 3, you have to type Python 3 for the interpreter rather than just simply Python. So, okay. How many of you are using right now Windows? Anyone? Okay. Few hands. So, I hope you already have Python 3 installed on your computer. Okay. Because, yeah, I don't understand that thing much there, Windows. So, I hope it will work properly. Python will work, but yeah, open up the terminal or ideally. So, yeah, in, so, in our case, we are typing Python 3. So, this is the default Python on Fedora 23. That is Python 3.4. You have a question. Yes. Yeah. So, Windows people help Windows. Can anyone just help him? Okay. Okay. So, yeah, sorry. But my knowledge with Windows is pretty less as it is very much apparent. So, yeah. So, as usual, our first program, correct. What is that program? Hello world. Okay. So, yeah. So, this should work, correct. So, let's see. Syntax error. Missing parenthesis in a call to print. So, it is actually telling us what is the problem. That is, we are missing the parenthesis. But why? You all remember, correct. If you are, if you have done any Python 2, so you can see this is the first really big difference that in Python 3, print is a function where you have to provide the parenthesis. So, this works. Yeah. So, here is a small tip. So, this thing will work in your Python 2.7 also. So, if you have a Python 2, just try to do the same. You don't have to mod. So, if you write all your print functions calls like this as a function. So, you are making sure that that code will work both in Python 3 and in Python 2. So, can you please try it out if you have Python 2? Anyone with a Python 2? Perfect. No error. No error. So, what are the changes happened here? So, do you remember anyone knows what is a comma operator for our print statements? Anyone? Like, if I write here, oh, I need Python 2 for this. So, I am here on Python 2, by the way. So, if I write print, say, let me do a for loop. So, it will be easier for, but I can come back to it. So, okay. So, because there are new people, we will go see the loop only when loop comes. So, yeah. Skipping that part. So, this is our first program we wrote in Python 3, print hello world. So, for the people in Linux and Mac, so, how do we write, make it into a complete script? So, we say, may say, write hello.py. So, that's the most important part. You should make sure that this is supposed to run on Python 3, not on Python, because we found in many projects, even though the developer actually wrote Python 3 code properly, he just completely forgot and wrote by mistake or with the practice that, hey, you have been Python. And then someone else came back and saying, hey, I am trying to run this script for a long time, but it's not running. It's throwing all kinds of random errors. So, hello.py works. So, remember, if you are on a Linux or Mac user, always try to give user been Python 3 and mention it properly. So, it will pick up whatever is the latest system configured Python. So, in future, it will be like, for federal, it will be 3.5 in the next release. So, Python is a dynamic language that means we don't have to define the types, data types correct. So, we can just write a equal to 10. I can write b equal to 30. And then I can do maybe c equal to a plus b. And I do a print of c. Can you see it? So, I don't have to define the data type, but it works. But again, there is a nice funny thing with how language is handling the integers. So, I can do this also, correct? Or rather, let's do something else. So, I can do this. So, if you try to do the similar thing in Python 2, what will you get? Anyone can you try the same, dividing two integers in Python 2? Can you see the difference? Here, it's automatically. So, it's converting when it's required to a float. Correct? Is this okay? So, if you have any questions, please ask. Otherwise, I'll just go on. So, please ask. Okay. Coming back here. So, there are various kind of data types available in Python. We already saw a few of them. The strings are defined within double quotes or single quotes. Or if you have a multi-line string, you define it within triple quotes. If you have an integer or float, you just directly write it. You don't have to define the data type again. And obviously, we have Booleans. So, using this, we can actually check a particular condition. So, I can always write, there was a space, correct? I'm just checking values. If both the values are equal or not. So, I can instead of 1 equal to equal to 2, I can write a equal to equal to c, which is again false or a less than c, which is true because a was how much? 20, I guess. No, actually false. c is 1.5 because if I c print c, a, it's 1.5 and 20, correct? So, we can use these to write our conditions if statements. So, if a is less than c, is this okay? So, who are completely new to Python, by the way? Because otherwise, it might become too boring for, oh, good. So, you can try it out. So, rest of you, we are going, we'll go a little bit slow so that they can actually type and try out all these things. So, if you see here, there are these triple dots, correct? So, this actually means starting of the block. So, wherever you see triple dots, it means that you already wrote something on the top and then we used indentation. In this case, I used two spaces because I'm typing in a terminal. I just press space bar twice and then wrote this part. So, instead of, if I don't do, give these two spaces and if I try to write it on the, from there, oh, this will not print because c is again 1.5. So, I should do this instead. But again, if I try to start writing from here without giving any spaces, it gives indentation error. So, Python as a language will force you to write clean code. How many of your students here? So, if you remember or if you know your friends or even yourself, I did it before. When they start writing those for loops, the programs where you have one for loop starting from the left-hand side and the second for loop again from the left-hand side. And then you, after two or three loops, you can't even read and figure out which is where the source code. So, in Python, it will actually force you to write much cleaner code because whenever you have something like this, it will force you to indent properly so that it becomes much more readable. We can have an else statement, else colon. So, if the condition is to do these parts in the indentation, else colon do these parts in the second indentation. So, I will press enter and type something like this. So, because in this case, the condition is false, a is not smaller than c, a is 20 and c is 1.5. So, it came to the else part and printed that thing statement in this case. So, Python also has a special thing called none. So, we can write. So, when we define a variable, many times it happens that we want to check whether there is something is actually inside that variable or not. So, you can think about it like this that we are starting a new account. At the beginning, the account value is either 0 or none. I mean, depending on your code, how you want to do it, maybe 0. Okay, let's mathematically it should be 0, not none. So, it should be 0 and then with the transaction, we can put in either adding some money or deduct some money out of it. So, if I write, let's say, acc equal to 0 and then want to check if there is anything at acc or not. So, one way of checking it is if acc equals equal to equal to 0, correct. So, we are actually checking and many cases we have to check like a flag where you want to see whether this is true or false, the acc value. So, there instead of writing like this or where many places people actually write if acc is true kind of thing, you are not supposed to do this. So, for true value or false value testing, you can just write the name of the variable. So, what you can do is just this. If acc is there or not, coming to an example, I think better example than this. Let's say this and I can write if x, then wow. So, we know that x is false in this case, but I am not testing or 0. So, we are not testing x equal to equal to 0 or x is false. Instead, we are just taking the value of x if x in the condition. So, in the same way, we can actually write not statement if not x and then maybe I can write nothing like this. So, in this case, I am using another new keyword here not just to negate the value, whether it is, I mean, I don't have to explain not, I guess. No, it is checking the value, truth value. So, in python 0, none or for strings, empty strings, they are all false. So, if I had a name, let's say name equal to or name equal to say kushal and then instead of if not name. So, it is finding name is not true, correct. So, instead of this, if I had an empty string and then try if not name, read nothing. We call it now false values. So, null is much more of a c java thing, correct, I guess. C, I am not sure of java, forgot it. So, remember whenever you are actually, you will find many source code where it is people actually wrote if x is true, if name is true or not. Instead of that, you can just reduce it to if x. So, the next point is looping, what is looping? Again, we are going to do something again and again, correct, with some kind of either condition check or we want to do it indefinitely. So, the easiest way of writing a loop is while, while space some condition and while that condition is true, keep doing that thing. So, I can write while true, correct. This means it will keep doing that thing. When will this end? Anyone? Never, correct. So, it is actually printing again and again. I am pressing ctrl c just in case you do not know. So, you can press ctrl c in the terminal to get out of this nice loop. So, you can see this comes as ctrl c comes as a special thing called keyboard interrupt. So, in future, I hope we will be able to see it. Like in your source code, if you want to capture this, that if your users press ctrl c, then you can actually use this particular word. Anyway, so again more of loops. So, the easier loop is to actually print some numbers. So, I will take a number n equal to 0. Then while n is less than, let's say, 11, two spaces here because I am typing in the terminal. In your actual source code, you are supposed to give four spaces. So, that is also very much important to remember. Please do not mix between tab and spaces in your source code. Most of the modern editors, you can actually configure it so that while editing Python code, your tab means four spaces. So, if you use Vim, Emacs, GID, even Microsoft Visual Studio, I guess what is the name? Code. So, all of those or even sublime text, you can actually configure it very easily so that tab means four spaces, not a tab character. So, here I am using two spaces. So, print n and then maybe n equal to n plus 1. Correct? And you can see that I am following certain rules here. I am giving a space before and after the equal to sign. This improves readability. So, a basic common thing you should always try to remember while writing any program is that what will happen when you will not use this program in future or someone else comes and tries to use this program. In our office terms, we call it maintenance, correct? That you may think that you are the only person who are going to use that program, but it may also happen that after 10 years or after two years or even after two months, somebody else can find this program and can use it. So, for them this readability really counts. A basic example actually, I am saying a couple of years back, I wrote a small tool in python called jukebox. It is for the OLPC, one lakh of pot child project. It was mostly the audio-video player and I knew that it was there. It was actually used in many places, but suddenly one night, middle of the night, I see on the channel, IRC channel, some people suddenly pinging me with random names, calling me uncle, how can I do this? So, when I saw uncle, the first question was like, hey, can you tell me how old are you? And there are like kids from like 600, 700 kids from Latin America and someone in their school actually taught them how to use IRC, how to chat and told the name of the guy who actually wrote it and you can go and ask him questions. So, few of them actually already started trying to see how python works and they were asking python questions. In a complete opposite example where I work in Red Hat, in most cases the software we write, we provide support for 10 years and you can imagine that we can't remember after 2 days what we did 2 days ago. So, after 10 years if somebody asks me what you did 10 years ago in that software or somebody comes and says, hey, I have to maintain that code after 10 years and you did so many wrong things, now my life is over. So, that can happen. So, please remember when you writing, while you are writing any code that somebody is going to maintain this, somebody is going to use this. So, writing clear code helps. So, I am actually going to just press enter, you can see I just use indentation here. So, it is starting from 0 to 10 but now again a clear difference. If you are in using python 2, you can still print all of these in one single line. Can anyone tell me how instead of the same for loop and no actually changing the print statement. So, if n equal to 0, you put a comma at the end. So, here the comma signifies that there is no new line character at the end. But as I said earlier in python 3 print is a function. So, you can just put in comma randomly there, correct. So, is this okay? This is python 2 by the way. Yeah question. Can we write n plus equal to 1? Yes, but because then everyone is may not be familiar with that. So, I am writing n equal to n plus 1. Is it to read? It is the same. n equal to 0 again. I am passing and one more parameter here. Print n equal to within codes. I use single codes. You can use the double code also. I am passing it as a string. Give an empty space, one single character. But you can see what is the problem here because at the end also here it never printed the new line. So, I should have write another print here when we write it in a source code so that this comes always below. Is this okay? So, we are passing something n equal to some value. So, instead of space now you can try to use your imagination and put in something else. So, I do not know whether it is slow. Okay. I forgot to end the loop. So, here I am putting a broken heart maybe. Yeah. So, you can see a clear difference again if you use Python 2 before. In Python 2 strings are strings. And if you have to use something like this or any other language than English, you have to use Unicode, correct? Like if your mother tongue is not English, if you want to print something in another language, you use Unicode and then print that. But here in Python 3, we do not have that difference. So, it becomes much easier for us. We know that always our strings can handle any Unicode character. So, I am printing a broken heart which is coming here nicely. So, if you can type any other language in your code, in your computer, please try to do so. I will try one thing. So, I am writing Bengali. This is my mother tongue. So, another, I would say, fancy thing is this. So, you can even define a variable in a Unicode way using. So, this was not possible before. But this may make it very, very difficult for the future developers, correct? If the next guy comes from another country, what if he does not know how to read this? But he can do it. So, if I do now, correct? Yeah. So, you can actually write down your whole Python assignment in another language and just submit to your school teacher in case you want to have fun. Because it will still work. Yes. That will be fun. So, Python, there are various features of the Python language which makes it very easy to work on. And that includes couple of different data structures which we have inside the language. These things are nothing but a special way of representing the data and providing some method to use it. One of the most common one is called tuple, where we have some data which we cannot change in future. We define them using comma separated values. So, we can write, now if I see the type of A, it's tuple, correct? And if I do print of A, I can actually specify which thing I want from A, A0 or A1, correct? But if I try to do, it says tuple object does not support item assignment. That means this is read-only data. So, when are you going to use tuples? For the places where you know that your values will not be changed, mostly like constants, where you know that rest of the part of that function or the code, this will be like similar values. And even if you by mistake try to assign something, it will not be changed. And there is a fancy thing which we love to show off if there are like many people without Python knowledge is that something we call tuple unpacking. So, if I write A equal to 10, B equal to 20, and then swap the both values. So, instead of taking a third value or doing a mathematical calculation, we can actually use tuple idea. So, we can write A, B equal to B, A. And then if I see A is 20 and B is 10. So, if you think this is a super fancy thing, actually it is not. What it is doing is creating tuples both sides. So, comma here works as a creating tuple. So, this works like a tuple in this side and then it unpacks itself. So, the value of B after it comes to the right-hand side goes to the A and the A comes to B. So, we will see another error actually right now. So, B equal to A, this is normal thing, correct. But if I want to do, take all the three values out of A, what will be the way? X, Y and Z. Or I can just type X, Y, Z. See it is creating tuples. So, it is easier to write. We unpack the tuple. Every value went to the right position. So, what if instead of this, you type this? How many values are there in A? Three. So, again this is a common programming error you may see. Because many times it happens that we are using a library or module written by someone else and it actually provides more values to unpack and we think, oh, it is returning only two values. But instead of that, it is actually returning three or four or five. Except few keywords, yes. So, I do not remember all the keywords obviously and how many but, yeah, like float, type, class, true for, but yeah. Yes. So, now if I actually try to define a float, not in 1.5 words but if I want to use float, I am just opening easier. So, it is always better not to use any of the keywords. So, my book, I actually copy pasted all the keywords from the Python documentation there. So, that you know you should not use those things. And while naming variables, another good idea is name them as a full variable rather than n, write down number or account number or something else which actually makes sense. So, think about this. When you have a large program, so not a good idea but you can try this is that if you have a friend has a good program, big application where they are using, they are checking lots of conditions and stuff. So, inside the code, if you write this, oh, this is the keyword actually. I thought we could do this, no? So, yeah, let's see in Python 2. Yeah, so that's the difference. So, in Python 2, you can actually write this, true equal to false. And just put it somewhere in your friend's problem and then ask him, hey, it's not working. So, I mean, you can see in Python 3, so we actually stopped this, which is a good thing to know. So, that's the keyword. You cannot assign anything there. And print also always had another fancy way of printing things. That is, you can print a stream, let's say, multiplying with a number like this. So, instead of false, let's say, take something simple like this. So, using this method, we have all these nice programs where you can print those triangles like different ways. At least they give it in the schools and colleges. Is this okay? Any question? No, nothing. So, after tuple, so the next big data structure we are going to look at is called lists. From the name you can understand, it's the list of things. Because Python is a dynamic language, we can have any kind of things inside a list, any other kind of objects. So, I can write, say, l equal to within square brackets. 1, 2, 3, 4, 5, 6. So, this is a valid list. So, what is the mistake? Yes. And I'm supposed to give the spaces also. I did not, but anyway. So, if we see the type of l, this class list. So, as I mentioned before that this data structure comes with a lot of different methods in them or functions which you can use on the data. So, the easiest way to see what all methods or things available inside any object in Python or any variable, you can say, is to use a function called dir. Type dir and l, whatever you want to inspect here. It will give you all the things. There are a lot of stuff. So, I just did dir of l. So, I did dir of 2l. Correct. Because 2l is a valid object here, an integer. So, it will show you whatever things are there inside an integer. Yeah, okay. Good question. So, as I mentioned that these things are data structures, basically, the particular kind of classes and objects, classes which contains not only the data. Let's say in integer, it's not only the integer thing. The value itself varies. So, you can find, it contains various other functions inside. So, at least just by reading from it, I never saw how this works. But you can understand that if we have some byte data type from there, we can create an integer. It looks like so, correct. From byte to byte, things like that. And we can access these values by typing dot. So, I'm going to do the basic thing l again. So, I can append anything here. The method name called append. Just like tuples, we can see, access any part of the list. So, what will happen if I type this? Anyone? Error. Error. Correct. What is the error? Index error. List index is out of range. So, there is a function called length, len, which will help you to find the length of that particular list. It will work also on your tuple. So, using this, you can actually find out how many values are there. So, you can see that we can have any type of objects or data in a list, correct? So, we can use this thing like this. So, this list can be, instead of number or names, it can be a list of emails. It can be a list of images in your computer. It can be anything. So, the best way of learning programming, there are different ways, correct? People will say like learn the syntax, learn this, learn that. What I find which works pretty well for me is to learn the very basic of the language, just so that I can type and then have some kind of book or some document beside me and then try to do something useful with that language. Unless I can use that language for any practical purpose, I can't use it. So, what can be a very useful way of, let's say, list? We want to see what can we do with a list. So, I'll show you one more thing and then we're going to do something practical here. So, we want to print each and every value from the list, okay? So, we can write this, a for loop. For, let's say, word in L, the list name, print L. Oh, word. Is this okay? So, we're taking, we're saying that take this list, go through each of the values, assign them to word and then print word, correct? Is this okay? Yes, no, anything? This is okay? Now, a practical thing. How many of you are Linux or Mac user again, once again? Okay, couple of them. And rest of you Windows? Yes. So, let's say for the Windows first. Do you remember that DIR? How many of you used command line in Windows? CMD? Anyone? Okay, at least two hands. Okay, couple of hands. So, do you remember there is a command called DIR, what we call LS in Linux? What does it do? It will show you the files in your current directory. DIR, enter, it will give you, if you are on Windows, if you never tried that, try it out. If you are on Linux, get out of Python and you can do this. In my case, it's only Hello.py here. Or I can actually say something like this to see what all things are there inside my root, LSL, correct? It's a command. So, it prints out all the directory's files inside there. Is this okay? So, what about actually writing this of our own with the knowledge that we have till now? We do not know much of Python, correct? Yes or no? Yes, I'm saying. So, we're going to try to use the knowledge that we have with one more new thing. And then we are going to try to write our own LS or DIR. So, there is a thing called Python modules. Modules are basically libraries, of course, which are written already there, which you can reuse. In Python, what we call as batteries included. That means we have various modules already part of the standard Python language, which you can use in many cases. So, let's demo first. So, there is a module called OS. From the name you can understand. It's about the operating system. We import the module like this. Import space, the module name. So, if I do import space OS, correct, it will import the OS module. So, OS module, obviously, it has some various way many other important things. And there is one very small function called list DIR, LIST DIR. So, I can write, say, names equal to OS.LIST DIR. I can pass it an argument. Let's say, if I pass dot, it's same in both Windows and Linux Mac. What is dot? Current directory, correct? So, or if you don't have anything in the current directory, please provide a different path. And then I can write for name in names, print, name, hello dot pi. So, using the same thing again, if I actually write this and pass it a different argument, I'm passing n equal to space. It is giving me all the files and directories listed under my rule. So, you can understand that we actually wrote parts of our system command, correct, using Python. So, I mean, I personally found this is the way to, for me, this is the way to learn any language. Okay, this is the way to learn any language. So, whenever I actually try to learn any new language, I try to start writing few commands, few tools, which I can write very fast and see how the language works. So, where are you going to use this knowledge? Let's take another example. You can, with another actually module called walk function call, actually, we can do this recursively. We can find out all the files inside any given directory. And then you can actually think about writing a tool which will find you all the duplicate images on your computer. We do have duplicate images, correct? We take photos, we keep it in one directory. Next day, give it to someone else, we copy it again. And then you may want to find out what all images are duplicate. So, what do you have to do? You have to first find all the files in your computer, find them if they are photos or not. And then some ways, there are various ways for that to find out if two photos are same or not or if a photo already found somewhere or not. So, this is that names is the list. What if we want to test if there is any value inside the list or not? There are a couple of ways, correct? We can check the length. If there is no value, what will be the length? 0. So, you can say if condition, if alien of names greater than 0, correct? But if you remember, I said at the beginning of this, in the beginning of this workshop, I said for true value checking, we may do not have to write so many things. So, if you write, just write if names that will already check if there are any values inside names list or not. So, you can try it out, write names equal to opening and closing square brackets and then try it again. So, I will write it here, if names like this. So, it is doing the same true value checking. But instead of going through the whole finding of the length of the list and all those things, you can just check this. So, do you remember that like a few minutes back, we are trying to find out the files inside different directories. So, instead of writing the same code again and again, we can write a function and then just call the function with an argument. So, we can write it like this def def, this is the starting of a function. So, let's say our function name is find files and then path as a variable argument here. I can give four spaces or two spaces. I am using just two spaces here and then I already imported OS. So, I can write say names equal to, so now I can write let's say print directly say find printing flash tmp may not be good. I never closed it. So, like I am passing a different argument. So, we can now pass any argument here and it will work. So, if I just go back to the definition, is this okay function definition? So, in Python, because it's a dynamic language, you can return a tuple here in this particular case instead of a single variable. And there you provide comma separated values and all those values will be returned at the same time. So, we'll see that but even before that, so what if we do not provide any path? What if we just want to call find underscore finds? What will happen? Typing mistakes. Correct. It says missing one required positional argument path. Correct. Because we never gave the value of path. So, in Python actually we can say while defining a function, there can be some default values. So, instead of the previous definition, we can write now here what is the default value? Let's say dot current directory. If we do not provide the path, it will be always the current directory. So, now if I call it, I'm not sending any argument. Correct. So, it will automatically take a dot as the default value. It will execute on the dot. Is this okay? So, let us write another function. Addition add maybe. So, def add. Correct. Is this okay? So, I can do a minus also in the same way. Correct. Is this okay? Doing the minus. Yes. Yes, but I'm just doing it one step. One more step. Yes. What is there for? Okay. So, nobody asked this question. That should have been in the if statement because that's where we first saw it. So, we are actually saying like this is a block starting and this is the syntax says the definition of the starting of the block. Like if some statement condition or a function definition, that's the syntax. That's where you write a column. So, like the indentation is not actually. So, when you write a column and press enter, it actually expects you to continue this block. That's why it starts waiting with the three dots for you. Now, you define the indentation. So, four spaces which should be there and then rest till there is a blank line. It will all the indent or blank line alert inside the same indentation value. Let's say four spaces. It will get like all these blocks inside the minus. So, basically you will have the practice. Yeah. The blocks of the code structure. Correct. So, No, because variables will contain only the statements correct or assignments very well equal to something so you can define a stream and then you can evaluate later on. Yeah, Ruby is different. Let's put it in simple way. So, so actually another, so many people, many people who came from a different programming language, mostly from C, they keep asking why can't I use parenthesis? Sorry, what do you call it flower? Currently brackets or flower brackets. So, I don't know where I read it, but I found there is a very easy way of doing it. You can also actually use brackets to define a function. Can anyone guess how or you can use anything else like I'm going to use brackets now define in the function which was basically a no. So you type this has and the bracket, which is basically a joke. So in Python, anything after a has sign is a comment. So what we are writing actually a comment nothing to do with the program itself directly. But yeah, spaces indentation, yeah, it will force you to indent properly. You like, as I said, when we'll learn start learn how to code, we always write everything from the left. Correct. But Python will force you to indent if you want to nested loops. So, okay, looking back at minus. So what I called here 78 and 8. Correct. So let's say you wrote minus. I do not know what minus is. I know it will do a minus. But I do not know whether it will do a minus b or b minus a. That can be a situation. Correct. Let's fix this. Let's you are giving me a minus function. You're telling me it will do a minus b. Correct. Now I know 78 minus 8 should be 70. But this is what you wrote in your function. You get me this function. You said it will calculate a minus b. It is calculating a minus b. Correct. But the argument positions are different. You are taking b as first and you completely forgot to tell me. It can happen. Correct. So I'll try to do the same call again. Oops. That's not the answer I'm looking at. I'm giving a comma and a and b. But it is doing the opposite thing. So we can actually try to fix this problem with forcing people to give those default values in every function call. Default arguments. So instead of positional arguments like we just write this, you can always write b equal to, so actually I can just go back to the call. Where is the call? So I can always write a equal to, and I hope this might break this. So while calling the function, I'm actually telling which value is what. So I know what it called inside the function. So I'm just telling a equal to 78. Doesn't matter where a is and b equal to 8. So it will always give me proper a minus b. And if you want to know what is the signature or how it looks like, the basic thing. So you can always do this help and something. So in this case, let's say the minus function. It doesn't tell me much. Correct. It says module double underscore main double underscore minus b comma a. So there is something in Python what we call doc strings, which are part of this mostly used with the functions or modules, which will help you to document your code so that others or even you can understand it after some time when you are going to read it again. So the same function definition. Instead of writing anything else here, I'm going to write a stream, not a command. Remember, stream. So I'm going to write, let's say, okay. So now if you wrote this and if you gave me, then I can actually do help of minus. And it tells me this is the doc string. Is this okay? So when you actually read any other module, when you go and read the help documentation, this is how they actually wrote those documentation. They wrote doc strings. And instead of that double code or single code, you can use triple codes to have a multi-line document doc string. So please remember that most the functions the code you will write always try to write the doc strings for those because that's how we are going to, it's going to help not only you, but your friends also who are going to use or read that source later on. Another small trick, people here still can pass this in this function. They can pass 8,70, correct? For BNA. But what I was saying at that moment was that you can force people to make it cured only. That means they have to say A equal to something, B equal to something, or B equal to something, or A equal to something. So I can write something like this. Now if I do minus, so I am calling the same function again. So this is what I defined here. I am calling the same function. But now I am forcing people that they can't just call it arbitrary like this. They have to tell which value is what. They have to say the keywords. So they have to write either A equal to 90, B equal to 34, or B equal to 90, A equal to 34. Please try it out. This is one way of forcing people, making sure that they call with the right arguments. Is this okay? What for you? So this is a new thing, a complete new paper. So part of the language. So you can actually put it off as an habit if you want to in your function so that everyone, whenever they call your functions, makes sure that they call it cleanly. So in this case, all those, it is a part of the language syntax that when you are writing it like this, or defining a function, this will make sure that you cannot pass any positional arguments in this particular case. That is, you cannot just write 90, 20, 34, or A, B, C, D. That will be blocked by this if you write it in this way. So that's the easiest to wait to understand right now. Do you have to do that when you do the start? Yeah, because without default values, they are again positional arguments, correct? Default values. So that means I can do minus B equal to 90. Yeah, calculate because A is 0. So another nice thing about a language like Python is higher order functions. If I remove that whole term, it basically means you can send a function as an argument to another function. So if I write, let's say in this case, I know that I will get a function. It can be either add or minus in my case. And I will get also two values. If V1 is greater than V2, nested indentation. If V1 is greater than V2, I want to minus it. So actually not minus it, but I know that whatever is function, I'll call funk V1, V2 else actually wrote wrong thing. So I'll press control C and do it again. It doesn't matter for add because add will work, correct? And I also forgot to write the return statement here, obviously. So I'll press one more control C. This is where one should, you know. So here I defined a function called high. It is taking the first argument as a function, funk. We don't know what it is. But if the next value V1 is greater than V2, then we call like this. Whatever is the funk, A equal to V1 and B equal to V2. And otherwise we call it just V1, V2. So now I can call high and we had that minus and then say 70 comma 45. And it's actually did a minus, but if instead of 70 comma 45, if I do, let's say 7 comma 45, it will try to call it this way, correct? Which is wrong in this case. So we can just pass say add 7 comma 45 and it's actually calling this. So there are a couple of useful functions like this in Python already. One of them is known as map, which you can use on any another list to end up using a function. So let's say we write a function say is square and N return N into N. Is this square? No. Yes. Two. Huh? Thanks very much. So N into N and I have a list A equal to 1 comma 2 comma 3 comma 4 comma 5. Is this okay? Now I can say map square. I'm sending the first argument as the function and the list. What will it do? It will take each value from this list and call that function using that. So and the output is actually a map object. So here is the difference again. So in Python if you call this output will be a list, another list. Here we are having a map object. So I can say this. I can then convert it back into list. So you can see that we took each of the objects from that list and then applied the function square on it and get the square values. So I'm actually not even showing the couple of major data structures. Like the major one is obviously the dictionary dict in Python. So I'm not going to go into that right now because we have another half an hour I guess. So I'll try to give you another small problem. So do you remember anything from the training? No, not that one. They like one. We already did. Yeah, no, but anything else we can show them the rest of it. So because unless they write code will not be helpful. So yeah, before I give you the next problem actual, let's look a little bit more into strings. So I defined a string here and there are various functions available within the strings. Two simple ones are either starts with or ends with. So using these two functions, you can check whether the starting of a string is another string or not. Like, let's say I can check whether a started with thus or not. Is this true or false? False, correct? A is crucial. So this is false. But if I check ends with this is should be true. Correct? Is this correct? Okay. Can you understand this? So now using this and if you remember that OS dot least air. Correct? We can try to write a function which will find us all the let's say photos in a directory. So for example, if a directory contains 20 files out of that, say seven MP3 files, some other random files and two photographs and using your source code, you want to write a function which will find you only the images. Correct? So for our problem, we'll make it even easier. Our images will be only JPEG photographs. So ends with dot JPEG. Correct? In small all standard. So let's try to do that. This is the current directory. I'm going to copy some photos from my wrong. So do you have any photos on your computer? If you have one or download anything from internet, any of the dot JPEG file one or two and drop it into the same directory where we are writing our code. Like this. So in this example, we have at least one Python file dot pie in the same directory one dot move. That is the movie and couple of JPEGs. Correct? Dot JPEG files. Now let's rewrite the same function. And let's call it. I'll write a write the function definition. The starting. Let's write a first I have to do import OS. And then def find images. Can anyone? Can you try to write rest of it so that we can only find the images. And to use it, if you need to know what you should use, you should use in sweet the string. So the idea is you find all the files in that directory. And then find out what all files ends with dot JPEG. So can you please try to write that code? No. So that's why we're calling a dot or the name dot ends with. So if the name only ends with a dot JPEG, then only it's a photograph. Correct? Basic idea. That way. So you remember you have to remember few things how to do a for loop like for file or for name in names. And then check each name if that name is ends with dot JPEG or not. If it ends with dot JPEG, then just print it. That should be the algorithm for the steps. Try it out. So tell me if you need any help. So anyone already done it? Yeah, perfect. Is it working? Yes. I know it is for one person. If you need help, please. There are a couple of parts we can help you. So I don't want to type it by myself because I want you to write at least that type of code. If you find any problem, we will help you out. Just ask. I think it's for the students, the kids. So you can try to do at least one thing at home later on. There is a project called Virtual Box. V-I-R-T-U-A-L-V-O-L-C-E-N-T. You can download and install on your Windows machine. And then you can create virtual computers inside your Windows box. That's an easy way to install Linux on your computer. It's really slow. That's less a virtual box issue. I think it's more of Windows, I guess. Yeah, everything is in those boxes. No, I should not say that. That's not always the case. But yeah. So unless if you don't want to install, if you don't know how to install Linux on your computer, that's maybe a good way to start using Linux. Because most of the development of the rules and things happens over Linux computers. And even your Android phone actually is nothing but a Linux system. So if you learn Linux now, it will really help you in future. There is a very slow button here. As far as I remember, it has very slow buttons. Some of you are writing actually the golden thing for Android. That would be fun. Just type it out. So this is what it does. So first we are taking out all the names, a list of names of the files. Names equal to OS.East here. Then just going through the whole list one by one. If the name ends with .jpeg, correct? So print name. Is this easy? Okay. Now there is a small thing if I can enter. And then I have to call it. But anyway. But we know that the image files can be more than .jpeg, correct? It can be capital .jpeg. It can be let's say .png, correct? It can be .sg, different file formats. All of them are valid files. So you can actually check the existence of a string or sorry, wrong thing. Existence of a particular object inside the whole list. So I can rewrite this same function again like this. If name in a list. So here I can write .jpeg, .png, correct? So we are checking if the, actually this is wrong. Sorry. I don't know what I was talking. So, okay. But there is another easy way of doing it. So I'll go come in this. But I want to check if the name ends with in any of these cases. So one common thing here is that how many characters here? They end with four characters. So we want to check the last four characters of the names is one of these. So I'm actually going to remove this line and I'm going to first check the last four characters. So this is called slicing. We can slice a list or a string. So we can take parts of the whole list. So I can say last part equal to name. I guess this is the right syntax. So the easiest option is to print. So yes, it can give me the last thing. So let's go back to the function. And now first of all, I can, I know that the file names can be in capital correct. So I want to make them lower case first. So I can just say, let's say again last part equal to last part dot lower. So I'm actually creating a new stream here with the lower case or lower case. And then checking. Thank you. So as you can see the biggest mistakes are the biggest bugs in any program is always the typing mistake. At least in my case, I need to print the whole name correct. Only the names. So if I just go up, that's the function here. I'm just finding out the last four characters. I can actually even go for the last three characters also if I want to. But this is better because I want to have that dot as the part to find out if it is extension or just name. So we actually organize an online summer training. We means the Linux user group I founded almost more than 10 years ago. It's called DGP-LUG summer training. In the training we teach people, mostly students, but people right now coming from all over the world, how to become an upstream contributor. So the idea is there, it's a three months long training. It's a training program. It's not a competition. There we start and everything happens over internet on something called IRC. How many of you actually used IRC before? Internet relay chat. Okay. So if you Google, you will find more about IRC. So it's an IRC based online training for three months where we start teaching about first communication, how to communicate over many lists, IRC chatting and everywhere. Then different tools. Then we teach about documentation, source code management, that is, get, market real, everything. We teach many other things, but at the end we try to help people to use Python to solve daily life problems. So we do not define the problems. People come up with their own problems like at the beginning we do, but after that people try to solve their real life problems. Things like somebody wanted to upload the same image on Twitter and Facebook at the same time. Or let's say you have a directive full of images and you want to reduce or resize them, all of them into a smaller image, all of them, but with a single command. So you can use Python to do these things. So we actually organize that summer training. So this is the page. I don't know if you can read it. So in this training we also get various upstream developers who come and give talks. We call them guest sessions where you can directly talk with the people. And even though last year also we tried to have Guido, but the timing never worked out. So we didn't contact him at the last moment. But I hope he will be able to come down this year. So we need to talk to him first. But there will be many other upstream developers who will come and give talks in these sessions. So if you have free time, if you want to connect, so those will start a little bit early because Singapore is two and a half hours ahead of us in India. That generally starts 6.30 PM in Indian time. Oh no, so it will start late. 6.30 means here it is 9 PM. Yeah, so it will start at 9 PM your time here in Singapore. And it's a three month long course where we teach. We'll make sure that if you continue, we'll become an upstream contributor to one of the open source projects. And that's the end goal, that we want people to contribute more to open source. And we use Python as a tool there. So if you have time, if you want to learn more, you can come to that training. And as I said, this is the book I was following roughly because it contains a lot of things which I never talked about. If you already know programming, you can go through this book in couple of hours. And I try to put up whatever I find useful into this book. It's called POMbook.Vidadox.org. Many times I found that there are some questions asked in interviews. So I tried to put all those things as part of this book. Whoever came up, they asked me this in the interview. Okay, let's put this in the book also. So whoever will read this book will understand those things. So feel free to have a look at it later on. This is me at Twitter. And this is my mail ID. So if you have any questions, anything, feel free to contact me either on Twitter or drop me an email. I may not reply right now, but I'll reply after I go back home. That is next week. If you have any questions, you can feel free to ask me. Any questions, anything? If nothing, then we can actually close the workshop. Thank you for attending. So tomorrow we still have the Python track by the way, people. So morning there are a couple of workshops. There is another talk, at least one talk in the afternoon and then more workshops. So please remember that the Python track will happen tomorrow also.