 Welcome everyone to this Python workshop. We will introduce some basic grammars of Python. And maybe if there are more detailed discussions, we can decide what topics are we going further. For example, data analysis or image processing. So let's get started with this URL. So there is a basic tutorial of Python. So please open this URL. So what operating system are you using? Windows, Linux? Does anyone of you use Linux? OK. And OSX? OK. The Windows users need to install Python using the banners. So it can be downloaded on Python.org. Since Python 2 is going to be obsolete at the end of this year, so please download Python 3.x. So now the major version is 3.8. So please download this version. For Linux users, you can use Python 3 and Python 2 directly. It's already installed in the system. So I did not say anything OSX and Linux users. They already got Python installed. Convention. It is a convention. So programming language always starts with 0. And the last object is the length minus 1. Is everyone following me? OK. Let's go further. The total here is a variable. And if you type total equals to 0, that means you will create a variable in the scope of Python. And the value will be remembered. For someone who has more experience about language, I should say that this is an assignment of a variable. But in some other programming languages, the assignment is quite different from binding. In other languages, if we bind an object to a variable, it means that the object itself cannot be modified. And the assignment will create a new binding in other languages, for example, scheme. Python here is not running like that. The virtual machine of Python does not run like that. And in Python, you can explicitly delete a variable using DEL. You can try that. If you want to see what variables you have, you can type DIR in your Python program. That's right. Everyone gets the same result of 11. Do you have any questions? Yeah, right, total is a variable. You did not write total equal to 0 in previous. You see here, where is the i is a variable. You got an i? You should check out your code. Only the space in the front of the line is critical, and the others are not. So does everyone get the same result? OK, this problem is the first time I have experienced it. This is actually from my understanding for different programming languages. It is really a bad design. There are a lot of defects in Python design. So Python 2 has some defects. And Python 3 is so part of them. But still, in my opinion, Python is not a programming language for serious development. In my experience, I use Python for quick and dirty works. For example, for corollars and text processing. But for serious programming, I use Scheme and C++. C++ has its standard, and Scheme has its standard, too. But Python is not. So you can use Python in different situations, of course, but take care of the defects. So let's go further. Does everyone get the same result? OK. Do I need some explanation? It seems pretty easy to understand, right? Now let's go further. Let's go to functions. Function is a pretty important abstraction of programming languages. In capture something inside, and we'll have a simple input and output. When I write programming in assembly language, I do not have other programming experience. So that programming itself is kind of manipulating different registers. So after that, I learned the programming language of C. And after that, I learned the functions. And so it is pretty important for programs. So you see here that the input here is named, and you will print the hello with the name. So for my experience, I do not use Python in interactive shell very much. So I did not notice there are differences between interactive shell and running script. I think it's not a good design. It's actually not. For my experience, I have no about many programming languages. I've never seen anyone like that. Oh, good design. Always write Python scripts. I use Emacs. Emacs is an editor. It's a famous editor, one of the best. Here I use the function of exec execute. So this is using the Python virtual machine itself to interpret the code. So with that kind of approach, we can get the same result without a line between different statements. So exec is a pretty powerful function in Python. Well, with the exec, you can run Python code inside. You can create Python code inside of Python code. That means you can modify the running script itself to have some higher levels of that connection. In some rare occasions, you need that. When you want to create some statement in your running time, you could use these kind of functions. I think this is powerful. And that is called a dynamic of a language. It means it can be modified when you run the code. With some static languages, it cannot be. For example, the C and C++, everything is compiled. You cannot modify the running code when the code is running. You can try other statements like that using exec. See here, I use three commas to say that this thing is a long string. And the three commas cannot be in the string itself. So they will be quite clear and explicitly. So the strings in Python can be multi-line. With that kind of approach, three commas. Single code or double code are the same in Python. Shall we go further? So let's try conditionals. String is a type of the integer, but no, not the integer, it's a variable. And you can use the str.upper and a as a variable for that. Now we get a shopping list of this order. But if we sort it again, you can see that the order has changed. This is what we call the static fact, which is not a good design, too. In proper way, it should be implemented like this. If we type the shopping list.sort, we should get a new list with a new order. But the shopping list itself remains the same. So that is a good design. But this way is not a good design. It's not functional. And it's not right. OK, I can show you a proper implement of this function, a better implement of this function. I'll type it on my editor with a moment. This is a proper implement of sort. You can see that the z here is 5, 4, 3, 2, 1, and sort. It returns a new list of the new proper order. But if we type z, it remains the same. A proper way to do that is we can write this type of statement to use the proper sort function. So you can see that we use the copy.div copy here. We will create a clone of a with its pointer and with its data content and run sort function to the new list itself and return the list as a new object. So the A itself will remain the same here. So this is a proper way of functional programming, which is quite important. Also, the div copy creates a clone of this object and its content. So after this statement, there will be two copies of this list, and they are in different memory areas of the Python virtual machine. And we sort, only change this one, and this list in the memory remains the same. Yeah, right. Yeah, this is a proper design. It confuses me a lot when using this type of method. You should take care where are the set effect. The set effect is that when you call a function, the variable itself is changed. It's not good. There will be a lot of mistakes when encounter that kind of function. In other programming languages, some side effects functions have a naming convention. So when you use that function, you will know that there will be set effect inside that function. For example, Scheme use the emphasize sign to see that the function has set effect. But Python, no. No, it will be not sorted. The A will not be changed. Yeah, right. After this, here you can assess the original z here. But after z equals to sort z, you will have z modified for sure. It's just a demonstration of proper function demonstration. So it's a better way of using the function sort. The sort itself, to a least, sort itself is quite ambiguous. You will not, really in this code, you will not have, you cannot imagine that the least is changed, right? It will be quite confusing. OK, let's go further. So did everyone finish this? Have you ever tried removal? OK. I think the remove, well, it's a better way to create a new list, too. Oh, you can use the insert. There were insert functions. Let me show you. Insert, this is the index, and this is the content. So list is not array in C, so you can have any type inside, even the list itself. For Python assignment, the assign itself, it works like assign the pointer to the content itself, but it will not create a new object of itself. So if you want to create a new object, you should use the copy.dip copy. It will create the pointer and the content itself. So when you modify one of the list, the other will not be changed. The sort itself is a sort. It does not return anything. And the s1 itself is changed. You see that? The sort returns none. The sort returns none, but the s1 itself is changed. No, no, no, no, no, no, no. You do not have that function. You know that function. You can see that the sl or s1, sl. So the sl itself is changed. You can be equal to sl, and you will have the, and sl is also modified. So this is pretty tricky in programming. So if you want them to be different, you should use the copy.dip copy. Yeah, it's pretty tricky. It's not new variable. So he asked a good question. If we have assignment into different lists, whether the list itself is changed. So you can see that here the z itself is 543a21, and we assign z to a new variable, l. So the l will be a new variable, but you can imagine that the l itself is 543a21. And now we modify the first element of z to 999, and z itself is 999 for sure. But we can see here that the l itself is changed to 999. That means that the z and the l has the same memory locations in the Python virtual machine. So it's quite tricky. If you want them to be separate, you need to use copy.dip copy. I'll show you. So you can see that here the z and l point to different places in virtual machine. Not that. You need to know what you are going to do. Different kinds of assignment can be used to. No, no, no. The variable of integer is quite different from the variable of this. If you assign an integer, it will be a different answer. Here the b is 0. And then we modify a. The b itself is not changed. It will cause trouble for sure, but it will save some running time. Since when you assign a list to another variable, if you will copy all the content of the list too, it will create an image. In memory, there will be two versions of this. So it will speed it up. So when you use Python, you will know that you need to take care of this memory location. Pretty tricky. The other important data structure, dictionaries. In other programming languages, dictionaries refer to table, hash table, or map in C++ called map.