 Boleh semua orang dengar saya? Boleh melihat saya? Baiklah. Kita akan mulakan. Boleh semua orang datang? Semua orang. Saya ingin memperkenalkannya. Terima kasih kerana datang. Kami akan memperkenalkannya. Kami akan memperkenalkannya. Semua orang boleh dengar saya. Kamu boleh dengar saya. Kamu boleh dengar saya. Boleh dengar saya? Boleh dengar saya? Boleh. Boleh. Boleh dengar saya? Boleh dengar saya? Boleh. Ya, tolonglah. Terima kasih kerana datang. Saya akan mulakan sekarang. Lepas itu, saya akan melihat. Kami akan memperkenalkannya. Jadi untuk malam ini, Kami akan melihat Kami akan memperkenalkannya. Kami akan memperkenalkannya. Jadi kamu boleh meminta pertanyaan. Atau saya akan meminta dia. Dan Yang Yin. Dan Benda Benda. Dan Dimana Linda? Linda. Ya. Terima kasih. Okey. Yang Yin, Linda dan Benda Benda. Kami akan membantu. Okey, sebelum kita mulakan event yang penting. Jadi kita ada perempuan. Dan kami akan baru memperkenalkannya. Dan apa yang kami lakukan di Singapura. Dan di sini, ini adalah pemeriksaan kita. Pemeriksaan network kita. Jadi jika anda melihat pemeriksaan ini, hanya memperkenalkannya. Mereka akan beritahu anda semuanya. Baiklah. Pemimpinan kami adalah untuk meminsipkan perempuan untuk memperkenalkan keadaan teknologi. Ya. Pemimpinan kami adalah untuk menggantikan perempuan dengan keadaan ke dalam keadaan. Untuk memperkenalkan perempuan dengan kemampuan yang mereka perlukan untuk keadaan profesional, untuk membuat keadaan keadaan dengan pemeriksaan network dan mentah. Untuk membuat pemeriksaan global untuk mendukung perempuan di keadaan yang mereka perlukan. Yang ini adalah pemeriksaan Singapura. Jadi, kita ada pemeriksaan network di sekitar 60 keadaan. Dan kami ada, kami menerima lebih daripada 10,000 pemeriksaan hari ini. Jadi, ini apa yang kita lakukan dengan pemeriksaan teknologi seperti ini. Dan jika anda ada pemeriksaan yang anda ingin melihat, pemeriksaan yang anda ingin mendengar, biar kita tahu dan akan berlaku. Jika anda ingin beritahu, anda ingin memperkenalkan pemeriksaan seperti ini. Biar kita tahu untuk membantu memperkenalkan semuanya untuk anda. Dan kita ada perkara ini yang disebut Jadi, kami ingin memperkenalkan dengan anda semua perkara yang berbeza. Okey? Memperkenalkan dengan anda jika anda memperkenalkan pemeriksaan, memperkenalkan pemeriksaan, anda akan memperkenalkan bersama-sama. Kami tahu bahawa perempuan anda sedap untuk berkongsi keadaan kami. Jadi, jika anda tahu perempuan anda yang memperkenalkan pemeriksaan, biar kita tahu, biar kita berkongsi bersama-sama. Okey? Kita memperkenalkan pemeriksaan yang diperkenalkan sekejap-kejap. Ia mempunyai banyak perkara sehingga ia mempunyai semua skolasi yang berbeza, semua pemeriksaan yang berbeza dan kita pun mempunyai semua pemeriksaan yang berbeza pemeriksaan, pemeriksaan yang berbeza dan pemeriksaan yang berbeza dan pemeriksaan yang diperkenalkan dengan Rimo Oko. Jadi, periksa. Dan ada juga pemeriksaan dan segalanya. Jadi, kami berkongsi sekejap-kejap. Jadi, kami berkongsi pemeriksaan yang berbeza dan kita berikan pemeriksaan. Bukan semua pemeriksaan, tapi kami membuat kejapan. Dan ada keadaan di sekolah. Kami mempunyai pemeriksaan yang berbeza. Jadi, berikanlah percaya. Ia bukan pemeriksaan yang biar kita memperkenalkan cara kita memperkenalkan pekerjaan yang diperkenalkan. Dan kita cuba memperkenalkan untuk anda. Okey, kami ingin berkongsi pemeriksaan Darwinshileps memberikan pemeriksaan yang cantik dan makanan kami sebenarnya sponsor oleh Pemeriksaan Pemeriksaan. Adakah anda ingin beri beberapa kata tentang Darwinshileps? Jacob. Adakah anda ingin beri beberapa kata tentang Darwinshileps? Dan saya mengikuti daripada daripada daripada Darwinshileps Dan saya akan mengikuti daripada daripada daripada Darwinshileps Kita terlepas sekerja sebab satu bulan lalu. Kami saja sedang mempunyai yang kami buat. Kami dapat mengulangkan juga kepada kepada kami dengan sukar perempuan menangkati perempuan dimanusing Saya sangat terkejut dan kami bersuai It's also the same language that we learn in kids through playing the more playful challenges with Robust. I'm not sure if you're going to use Robust tonight, but maybe, yeah, that's something for Robust. Thank you very much, Julien. Thank you. Okay, now, if not for the loo, let's start. Okay, my name is Julien, and I've been coding in Python for the past two years. So, yeah, Python is a very powerful language. And still, this is, before we start, everybody make sure that install Anaconda or Python 3 and Jupyter Notebook. So, we've been using Jupyter Notebook for our tutorials and our workshop today. So, make sure you have cloned or downloaded the repository. All these links can be found on the mid-top page if you need to just click or just go to the GitHub, www.pyton-tutorials, the slides are up there, you can click on the slide as well. And the Wi-Fi password, if you haven't had the Wi-Fi password, grab it now. If you... 10 seconds. Okay. Everybody got it? I'll move along. If you haven't got it, make your hand. Why do we use Python? Python is a very powerful language, and I say I find it to be so. We really stick to these rules, and why people choose Python is because of the consistency, the readability, and it's easy to change. It's functional, object-oriented, which is the way forward in terms of our programming languages, and has a complete set of code style guidelines and Pytonic idioms. I'll show you where to find the later. Okay. Just a show of hands. How many of you are beginners? No coding background. Okay. How many are programmers? Professional programmers. Okay. Terima kasih. Okay. It's not quite a mixture. Everybody is a bit clunked around. So if you have questions, raise your hand. Look towards our assistants. Chibangi is over there. Yangying is over there. I think maybe we need to spread out a bit. Because Yangying, you have the past, right? You need to stay near the door, right? Linda, bila anda ingat jika anda bergerak ke depan? Terima kasih banyak-banyak. Terima kasih, Linda. Okay. Saya akan beri anda tangan dan biar saya tahu jika anda ada pertanyaan di mana-mana. Okay. Beri tangan dan mengerangkannya kerana ia sedikit susah untuk saya lihat jika anda tidak tahu. Okay. Apa maksud anda untuk mengucapkan? Koding eksplisik. Itu bermaksud ia lebih jelas tentang koding anda. Okay. Satu kata-kata. Jangan mengucapkan segala-galanya ke dalam satu kata-kata. Perubahan, mengubah bagaimana keadaan yang dipercayai. Ketika keadaan yang dipercayai di Python adalah bagaimana kesebekanan anda. Memahat dan keadaan yang dipercayai. Jadi jangan mengubahnya. Dan mengubah bagaimana yang digunakan dalam keadaan yang penting. Kerana Python adalah sebuah keadaan yang berubah. Anda dapat melakukan semua ini, tetapi mengubahnya. Jadi, tentu saja. Bersyukurkan program berbeza. Dan mengubah dan mengubah keadaan yang dipercayai di Python. Anda dapat menunggu. Dan jika anda perlukan dua, jelasnya anda akan melakukannya. Tetapi jika anda tidak perlukan dua, anda akan melakukannya. Sangat mudah, kan? Dapat keadaan keadaan yang dipercayai. Okay. Ini adalah apa yang kita akan lakukannya. Dan jika kita selesai ini, kita akan melakukannya. Okay. Tetapi sekarang, kita akan melakukannya bagaimana untuk melakukannya. Kita akan melakukannya ke dalam Python, keadaan keadaan yang dipercayai, keadaan keadaan yang dipercayai, keadaan keadaan dan modulannya. Jika saya akan melakukannya dengan cepat lagi, tekan tangan dan melakukannya. Okay. Kemudian jika anda telah melakukannya, kita akan melakukannya dengan sedikit latihan dalam keadaan kerja. Okay. Jadi, mari kita lihat. Okay, jadi ini adalah jupit yang telah dilakukan. Jadi, jika anda telah melakukannya, anda akan melakukannya, memilih jupit yang telah dilakukan. Semua anda telah melakukannya, anda akan melakukannya dengan sebuah page seperti ini. Okay. Jadi, jika anda disini, jelasnya, memasukkan untuk jika anda telah melakukannya ke dalam github repository. Teruskan ke dalam Python Tutorial, dan masuk ke dalam folder yang tidak terdapat. Dan kita akan melalui segalanya dalam folder ini di sini, untuk bahan basis. Mari kita mulakan jupit yang telah dilakukan. Bagaimana membuka jupit yang telah dilakukan? Semua jupit yang telah dilakukan adalah PYMB extension. Okay. Dan kita hanya menghidupannya, dan membutuhkan untuk jupit yang telah dilakukan. Seperti itu. Okay. Dan kita cuba. Sejauh ini. Okey. Jadi, jika anda mahu mencuba jupit yang telah dilakukan, jika anda mahu mencuba atau mengenai jupit yang telah dilakukan, kemudian, anda boleh sebenarnya mencuba jupit yang telah dilakukan daripada pilihan komand. Dan kita hanya mengenai jupit yang telah dilakukan, seperti itu. Ingat jupit yang telah dilakukan dengan PYMB. Kemudian ia akan memasukkan perkara yang telah dilakukan. Jadi, anda boleh mengubah nama jupit yang telah dilakukan dengan hanya mencuba di sini, dan hanya mengubahnya. Dan kita lihat, setiap jupit yang telah dilakukan adalah pilihan komand. Anda melihat pilihan yang telah dilakukan di sini? Ini bermaksud ia mengambil. Jadi, saya hanya mencuba. Kemudian anda menunjukkan, okey, sekarang ini adalah pilihan yang telah dilakukan. Dan saya berada di sana. Di sana. Dan nama jupit yang telah dilakukan, anda harus melakukan itu. Jadi, setiap jupit ini boleh menjadi sebuah langit yang telah dilakukan, atau ia boleh menjadi sebuah kode di sini atau sebuah komand yang betul. Anda boleh hanya mengubahnya di sini. Anda boleh mengubahnya ke sebuah kode, kemudian ini akan menjadi sebuah kode, kemudian ia akan berubah. Berubah sebuah kode, untuk mengubah sebuah kode, berubah dan berubah, atau mengubah alih masak, anda akan mengubah sebuah kode dan mencuba sebuah kode di bawah-b bawah. Mari kita cuba memasak dan belajar. Setelah anda menerima diri, setiap diri yang anda menerima, ada sebuah nombor di atasnya. Ini membantu anda mengetahui bahawa diri telah menerima. Bagaimana anda mempunyai output? Mari kita memasak dan menerima. Itu output anda. Output akan dibina di bawah diri. Jadi saya mencubanya anda untuk membuat diri dan menerima apa saja yang anda suka. Justi menerima sebagai meraj tangan anda. Jadi seperti ini. Kita menerima seluruh diri. Atau memasak dan menerima. Okey, menerima. Anda akan menerima diri. Apabila anda suka, saya akan mematukan y dengan 3. Dan beritahu saya apa y itu. Okey. Sama seperti itu. Jangan lalu-lalu bergerak selama anda berjalan-jalan. Di sini, kata-kata ini beritahu saya apa yang kata-kata. Dan ia akan keluar dalam perjalanan seperti itu. Ini adalah kata-kata 5 yang telah saya bergerak. Jadi ada kata-kata nombor 5. Bergerak selama anda. Tengoklah apa yang ia lakukan. Jadi setiap kata-kata adalah satu sesej. Jadi setiap kata-kata ia bergerak. Ini adalah kata-kata baru. Jadi sekarang ia bergerak. Anda boleh kembali ke sini. Dan ini akan beritahu anda dengan sesej yang lain. Di sini ia bergerak. Sekarang hanya kata-kata nombor 5. Nombor 8 bergerak. IPYP bergerak. Dan setiap kata-kata anda bergerak. Setiap kata-kata anda bergerak. Anda bergerak lagi. Kata-kata anda masih di sana. Tetapi jika saya bergerak, ia akan bergerak lagi. Sekarang ini adalah kata-kata baru. Kata-kata anda dapat melihat. Baiklah. Anda dapat mengubah kata-kata nombor. Dengan bekerja, setiap kata-kata anda hanya bergerak pada kata-kata baru. Kerana kami bergerak. Setiap kata-kata anda adalah satu kata-kata baru. Jadi di sini kita bergerak. Maaf. Maafkan saya. Di sini kita bergerak. Jadi jika anda mahu mengubah kata-kata, anda boleh mengubah kata-kata. Maaf. Kata-kata kami sudah lisik ke kata-kata yang sama. Sekarang ini adalah kata-kata. Baiklah, anda dapat mengubah kata-kata itu. Itu harus diambil ke kata-kata. Bila anda mengubah kata-kata ke kata-kata, dan kami akan mengubah kata-kata ini. Kepuluhnya kami mengubah kata-kata baru. Baiklah. Anda menggunakan kata-kata? Untuk menggunakan crashing. Bukankah anda memutilakan kata-kata? So Anaconda, you can install arm using Anaconda as well. Sorry, the question is how to install a different kernel, right? Install arm. Anaconda is a great tool that way. It helps developer cycles to install everything. Yes, in that case, there is another way. It's basically you need to install the GUI version, the notebook for arm. You need a couple of GUI. So if you download using Anaconda, or you install Jupyter Notebook separately. With Anaconda, you can use Anaconda and basically install the additional modules required to run it on notebook. Other question? Any question? Let's look at syntax. Smiling, just click on the syntax, IPYNB. Let's go. First thing about Python is that it's an interpreter language. It's not a compiler language, right? So we have an interpreter. It's a line structure. Basically it treats each line as part of the syntax. So the end line does make a difference. Each logical line is terminated by the new line totem right there. So as we go along, again just hit SHIFT Enter and you run the code. So now we have X equals to 1. We just assign. We are just assigning 1 to X. But if... Sorry. Okay. Test. Sorry. So we... We can have empty lines. Langt lines, Python will ignore. But basically if it's not blank, it will treat it as one line command. The same as you would on a command line basically. Once you hit Enter, they treat it as one command, right? We can join two lines. How you do that is basically have a backslash of the line. Just keep running it. Then you'll see, this is example like joining right there. So this here, this is one single expression right there. Basically if you want to test the code just again add a cell right by what you would like. See. Like so. Right. Langt lines are ignored inside the brackets. So if I have done this, that works. Okay. Multiple statements can go in a single line. If they are the same sort of statements you think that it makes more sense to read it in one line by all means, right? All you need to do is put a semicolon at the back. And this year we have 1, 2, 3, 4 statements in one line. It's very important in Python. Basically each of the same indentation as long as it's continuous is treated as the same block of code. So there's no curly braces. So you need to be careful with your indentation. A tab is not the same as four spaces. A tab is a tab space space. So if it's a tab, make sure all your indentation for that same block of code is all tabs. Yes. Is there a question at that? No. Okay. So you can mix your tabs and spaces as long as they are the same like that. Okay. So this here, this block of code is still within the same. This with the same space. These four spaces is treating this as the same block of code. And this here, from here onwards, they are the same. It's treated as the same block of code. So a couple of style guides for you to follow. You can read it on your own time. And just a couple of practice. Just keep, if you think shift enter, these are the, these are the list of key words in Python. Just to go through it quickly. Force none through n, s, assert, break, plus, continue, death, as in define, delete, LC, else, except, finally, for, from global import in East Lambda. It's a very interesting keyword. We'll look into that every time today. Non-local, not, or, has, raised, return, try, okay, those are the key words. And there's a couple of very helpful built-in functions, built-in helper functions we have in Python. These two directory and help. So if you keep directory, it will give you whatever is in that session base screen. And basically, if you have a couple of functions that you want to know more about, if you want to do. Pre, for example, do that. And you give you the directory of that function. What the attributes are, the modules functions in that particular module or function. Then there is a help. Similarly, if you put in print, like so, it will give you help for the print. Or, you can do that. And this year, put in whatever you like. Let's say if I want. You give me the string object. Can keep going. Until you hit stop button here. Then, let's carry on. The next one, basically, I've already touched this one. You can do that as well. Okay. Whenever you are in doubt on how to be Python-y. You can refer to this. Just type import this to give you the Zen or Python. Keep this at the top of your mind. I think it's quite useful. And this is everything to do, basically, how to be Python-y. How to write Python-y. Need consign swing. To go up with import and parenthesis or just be positive. Import is no parenthesis. That's it for syntax. Any questions? Yes. In this case, I'm going to do. Yes. If if you try and nothing has come out, go back to this one with the help, right? Hit stop. If your help is still running, hit stop. Hit stop. It will keep on running until you hit stop. This, you can also run in your command line, right? So basically, if you start Python on your command line, if you just hit Python or Python-y on your command line, you can write all this command line. It's the same. Yes? Okay. She just personally write in import this. But I've come to import this. She made the import for Sorry, what was the question? No, under the import, just act like some poetry that comes out. Yes. I don't think you want to come out. You're still on mark now. You need to change she's to a quote. Then try to write as we have. And then just keep she and we have in the draft. Now, writing is very risky because you don't have to define it just to be just say away but sign the value automatically notice what you want to do. We're all black numbers using none instead. None and none is actually two different types. But none itself is treated as a budget type. It's not treated as an integer or a string or whatever. It's treated as a type itself. It's a data type. It's not even none is separate. But none is a type. Obviously you just need to do that. Let's say okay but each any data type per cast in C. Just to say at least I want this to be done it should be treated in a really wonderful that way. And this year you just keep doing that or three variables are assigned together same as C. And another thing is what we call an unpacking in Python where you can assign different types in one single code create a new self test it out see what is the element country right here we can see it should be a billion of load and non-strength. And basically just now I told you about the dating keyword just use date and it will give you that it is two garbage collection in effect. So if I normally that variable just do a date same as thousand space powerful in Python so that flow through the difficult months we have the stream obviously of this change however you like see what it will do in us and we'll go through this but you want to go through this so yeah similar in stream you can just use a fast sign basically just on the next stream in just the first we have a stream so you're only printing the first character page this year you're printing the second the fifth the bing second to the bing basically the second zero one two three four right that's it if you're printing all the way to the end printing area in from the second character all the way to the end you can multiply your stream they just multiply the stream and you can use triple growth if you want to spend now let's go on the next couple will be the mutual objects you cannot just say okay I want the second character to be a one no you can't you have to change and I will so a list how do you create a list just use the simple method you can add various types object types in a list you have a stream here and in the journal float in one list so what do we use so we just gather together in the information associated with each other in a particular manner we put them together right here let's say we have our you know we have one piece for means yes so I think we have 17.2 and why have 30 samples together they should make sense together basically let's say okay so another way to create a list is by using this comprehension steps up this in this sphere we call it this comprehension so if you want to create a list of the codes of these symbols we create a stream that this here creates a stream of symbols this code here this converts a symbol each symbol in the symbols each symbol in the symbols convert it into a form and we have the codes it's a key value pair it will always have a key it will always have a value so right here you create a dictionary using the curly braces and like so we have a dictionary that has a name we move to Singapore the organisation is WWC city is Singapore and it has 1260 members that was about 2 weeks ago we give them 4 now then we have the sets the difference here is that this here we have the all key and value pair without the key and value pair we have a set again you can use the type this will tell you what the type of the data type is questions about the data type structures sets and what list list list is okay you will think of set like the mathematical set what is a set it is a group of set you can treat it as a mathematical form at least you treat it like an array no, these are not data frames so if you want to have an equivalent of data frame in R that would be data frame pandas there is a module called the pandas it's a separate module altogether it's a very big module pandas is very it has everything to do with data frames you can look it up we'll go through that actually not in this section probably in python 103 you understand about the sets and the list a mathematical set let's say this set is the BW code asian network so another set would be the BW code surface asian that would be a sub set of this set those are sets when we talk about a list think of it as an array it can be anything all together group it together it's not a set when you have a different data type you can use the different data types functionalities as you for a set you can treat it as a mathematical set you can manipulate it as you put any mathematical set no more questions let's move on we have operations so I'll just go through this quickly for those who have programming program you have no all these operations anyway just to show you it's very similar to see the basic ones are quite similar then you have your addition your subtraction multiplication division modulus exponent floor division and your Boolean still the same as C language assignment also the same feedwise operations also the same XOR once complement left shift or the same as C language logical operators ok this is not the same as C so we have alter the apparatus so if movement is in string these these are the keywords if in string then you'll be true ok the dark green born ones are the keywords not in man is not in women who code right there sorry stupid joke but so if this here checks if women who code is the same as lang women who code right these are the logical operators comparison same as logical operator but you use the keyword and none sorry keyword none collection types so collection types have their own operators as I said if you use a different data type you'll have a different set of operations for a string you can slice it slice from the 6 to the 11 right there so the string so we are slicing this string from the 6 character 0 1 2 3 4 5 6 2 7 8 9 10 11 11 that's called slicing this colon here is a slice operator so if you want to slice from 3 to 9 for every 2 sets this is what we do 3 to 9 every second data every second piece of data so we go through here 0 1 2 3 5 and 7 right there we can even access from the end of the collection we can sort it most collection type has sorted just try it out if function will return through any operation we call it an operation any function operation the same thing will return through if any of its member collection is true so if any of this is true it will return a true or it will only return true if every single one of them is true ok these are Boolean operators for collection types questions? right let's carry on so spring string have its own specific operations so all these are string specific operations right there concatenations multiplications upper lower capitalized center left adjust right adjust ok what's that fine index are fine fine because the the first i it finds it returns returns lowest index of the first i so if you look at this string here the first i is 0 1 so it prints 1 index does the same thing as that it gives a different error are fine returns the highest index fixing finds the i from the back from the right join same as any join split we'll split this string you can see it split this splits the line split line split the line you have partition partition based on i so we have part t and i o n strip l strip left strip like right strip replace and format ok all these are typical string operations that you can find then we have boolean string operations the previous one takes the string this here gives you a boolean return starts with n3 is alpha is digit is alpha the mark ok next we have a couple of operations that is for dictionary look for the keys returns the keys returns the values the items gets get the particular value of the key name pop basically it just means that you pop it is longer inside the dictionary pop it up of the dictionary set the default to be the default they say you are setting key in the dictionary for or to be given code it acts like get but it also creates a new key if it's not inside set default basically it means if or is not in the dictionary it will set this value to this key but if or is already in the dictionary it will do nothing it will return you the value of or ok next we have operations for sets this here will give you a better understanding what's the difference between a set and a list ok there's quite quite a bit here I notice that it can be a bit confusing because of the small screen but on your bigger laptop screen you should probably be able to read this quite clearly so we have WWC this is one set so these are all the cities in WWC Asia if I print Singapore in WWC Asia they say I'm asking if Singapore is in WWC Asia and yes it is all these are true values so this here is subset so is this a subset of WWC Asia it treats it as a set in medical operations we do that we check ok this is subset of what if this is less than or equals to WWC this here will also return true if it's equals but if it's equals and this here if I pass this whole subset in here this here will be false so all the medical operations also work on sets is it a superset this is also the same as a superset so if we do Singapore Manila Union we get a set it will be a union on your sets do an intersection on your set check the difference of your set we get this returns the difference of your set and the symmetrical difference right there ok and because set is a mutable object you can even modify your sets in place I can update this set this is also the same as doing an update I can do an intersection update do a difference update symmetric difference update add, remove, discard, pop I can even clear it ok we move on to so the key thing to note if you are not used to python is that yes spaces in front of your block of code is very important the indentation is very important so if we have an if statement make sure your indentation in front here is the same to indicate the same block of code if it's not the same it will give you an error right there so make sure it's the same everything is good and happy ok just keep keep it shift and turn we have our if and else if if, else, if and else questions? ok next we have our try statement try accept this is where your value error is so if I run that again if I move it so if it's a value error print and loop again ok pass statement so pass it means that I want to pass if I hit a run type error or a type error or a name error I just raise the raise key word will raise an error will try to raise a name error right there if as a name error I will print you can try it out just to let's say I put a 1 there basic this here it will raise the error at the end right there it prints notice that it will print this first it will print an exception has move by first and then only it will raise the error raise a name error if you print if you did not have this if you did not have raise you won't raise the error right and if your raise is before your print you won't be printing anything you have raised an error and it will have sticked out questions house works the same in a try statement try this except for as error otherwise you print this finally works similar to if you familiar with C language you have your straight statement or default would be the finally to this here we are defining a function divide right so we have a divide and if you do this division by zero we hit this just keep running we hit division by zero and always a finally raise an error but it will still execute your final clause yeah you can just try just create just create a cell try you don't see us executing have you run each of the function cell you run this cell and you run this cell you got the same output ah is it previous one this one here is it still running the wow loop you might need to stop your wow loop okay thank you thanks a lot okay next we will move into loops sorry too much if you can't remember everything it's there for your reference really just know that these are the typical things that you can expect to find don't have to remember every single thing okay next we have a wow loop so how does wow work the same as the C language you just don't have the curly brackets instead of curly brackets we have a colon right so we have your wow loop so 4 is again is different from our typical C or jawa language for this here we have a 4 and an in for each item in 3 we print the item for each item in range 3 we print x and x obviously will take on the last value because this is still in the same level for x in range 3 to 6 up to 6 again is from 3 up to if you see a range like this is from 3 up to it's the same as how we did the slicing previously the first item is from up to the second for x in range 3 up to 8 skipping every 2 words the same count this sorry or to run this for count else print so basically obviously this else works the same as in if statement if count is not less than 5 print same thing else works the same way in 4 loops break works the same continue basically if it's an even number just continue next loop even number continue last statement works the same as past in exception next we have iterators iterators is another powerful thing about python is that quite a lot almost every collection in python is an iterable so you can iterate it you can use it in a 4 loop loop swing and each iterator you have you can use the next operation let's try that okay so we have our vowels and basically each next will give you the next A B I O U if basically this here is reading the readme file open it as a file for each line and we are making this an iterable okay and making this into an iterable and using the n line basically can print each line questions about iterable? the most common usage it needs for iterables is to use in a 4 loop the other is to use it as what we call a generator basically iterable generator it will keep running it's a function that will keep running each time it won't go back to the beginning so to speak okay let's do it it won't be covered here but yes you can definitely nest an iterable yes you can nest iterable and if I'm not wrong, yes it can be internet as well yes you can nest an iterable you can have an iterable inside iterable yes next value of what? so you can use in a function I'm not sure I get your question yes yes you can use next in sets we're doing well okay next we come to modules so Python is an open source language so a lot of people in the Python community have contributed a lot of quotes and a lot of modules for your easy easy of use they create this module so you don't have to rewrite the functions again and again right the most popular module for Python is the Pandas so if you have installed via Anaconda these modules have already been installed for you so you don't have to but if you have installed yourself or if you need to install any module that's not included by Anaconda in the future this is how you do to install a module what this means is you go to your terminal or command line and you type pip install and whatever it is the module name right just type it and it will install or if you find that for some reason pip does not have the particular module that you want you can always try conduct install so this is just a different server they are quite similar but it depends on the package itself if the developer has put it on konda library or yes they put it on both the konda and the python installer packages okay so this is how you install a module once you install a module you can use it how do you use it you do an import same as we do import this we do import the module name do it in python is also quite useful if you are doing a lot of mathematical calculation it has pi it has the e it has the square root sign cosine radius and so on and so forth anything you can find a sign fake calculator you just need to import this map module another way to import module is to do import pandas as pn what does this do this means instead of typing pa,ndas, dot something something I just do pd dot something if I import pandas as pd I can I need to use pd I cannot use pandas because it really treat the pd as pandas so you can use pandas as another variable if you only want a subset of that module you can do that too because python is quite neatly arranged in that way each module can have their own sub modules this year it's just from PIL it's importing a sub module or even just a particular function you can do that too so now that I import pd import pandas as pd I can do this and you give me the version of the pandas that I have of course once you are imported you can do a help you can do a directory questions we have our last one which is a function actually we don't actually need to start with a function we can do our workshop first let's do our workshop first we will continue on after our workshop your workshop should be under your ws1 folder we have your word cloud okay who doesn't know what's a word cloud okay so a word cloud basically is better to just show you alright this is a word cloud word cloud basically put together all the different words and they put it in graphical format with the bigger words means a small frequently found okay so the more frequently found words are bigger the smaller less frequency will have a lot smaller word font size so that's a word cloud so for this workshop we will go through how to create a word cloud so if you notice it's blank just follow the instructions and do the workshop okay let's go through it so first a word cloud first you have to install the pattern the package the word cloud package give it a try cloud I believe it's not part of your regular anaconda package so you have to install it first so you have to do a keep install word cloud and then from there once you got it installed successfully into import right this here means that I haven't installed the map plot need very big map plot need very big what? oh it's okay ya we are not using pandas today I think those who install python 3 anacondas you need to do peep 3 install word cloud peep 3 this this differentiates between your python 3 and your python 2 it will install in your python 3 once you install this means I am installing it in the wrong environment I need to do a conduct install word cloud your command line for your windows oh no don't need don't need to restart should work so my mistake it should be from the word cloud library import so it's like so word cloud import word cloud follow the instructions I failed to follow instructions okay from word cloud library import word cloud conda doesn't work I think it's not in conda so you need a peep or peep 3 word cloud gcc fail conda install cloud gcc fail ya they don't have it on anaconda so that means it's compiling fail you install python yourself ya you install python 3 ya the one that devices are you running a different environment different you do have you do have administrator rights ya to where you install your python where I install python ya I install first you download anaconda ya ya and you have administrator rights when you install anaconda ya and now you have administrator rights for your disk correct so the problem is you need to install for your for your for your Sijaja ya ya they don't have for their Sijaja dependency hmm hmm hmm because I can use for the walk out okay for those who are running okay I see okay I think quite a few of you have compiler errors which I did not anticipate I'm so sorry about that if you do have compiler error you might not be able to run this workshop at this point you can go home and visit you need to install some compiler languages if you have Xcode it will be included in your Xcode and if you have Microsoft you'll need to download um .NET library if I'm not wrong hmm so don't worry about that I'm so sorry I didn't have to say that I'll just run through this to give you a few of what's going on I'm so sorry you won't be able to run this word cloud but I'll run through this okay just to give you an experience so this is what I do I install the package word cloud import the word cloud module and basically I made a text I've prepared this text I've copied this from our remote code website and I put it under www.codesdories.txt okay so if you look under here I would say you can choose here we have a www.codesdories.txt something like this so any text form we generate our word cloud using a text of given right so what I do is I just speed this text in to the word cloud I'll read it as a text so basically if I do if I check what's inside the text this will give me right this is what I have inside okay what I do is I plot it here uses the sorry so we have read the text so what I'm trying to do is play using map.lib sorry about that yes you can use any text no it doesn't have read you need a pdf reader to open the pdf so this year we are just importing map plot need pipelot.splp I'm missing a block of code here so ignore this one I'm just going to clear and this year I'm using the word cloud because I've read the text I've read the text inside the text so I'm generating a word cloud with 600 pixel width 300 pixel height using map plot need to plot the figure and that's it so this is just using the word cloud library to generate a word cloud I'm just passing me the text passing me the size and that's it I generate a word cloud it's here word cloud.to file because this year this is very cluttered so if I just want to limit the number of words to the ones that are more significant so I just put max word equals to 100 so this year we'll only display 100 words we'll post this on the github after this social for word clouds we can also put in a stock word so some of these words does not give a lot of meaning those words that are too frequent they don't give a lot of meaning so I want to remove them so I can create a list of stock words from word cloud it can import the list of stock words words like the and these are very frequently found words that does not need a lot of meanings if we can import stock words so we set the stock words we can also set a set of stock words it's okay got that makes no meaning to the word frequency and remove it so I add these stock words into here the easiest way is just lazy if you look through to your word cloud and see hey I want to get rid of this word then I just add it to my stock word and I plot it again you can see then it comes a bit later let's do something more fun a mask image and regenerate the word cloud using a mask so this we will call the engine looks like this is my mask image so let's see what it does so I generate this I just put the mask equals to mask right there I'll post it on GitHub after this session okay I'll just carry on with functions this is quite simple we've already seen some functions previously so a function is created using the keyword df says what we find so I'm defining this function is print function and I just have a very simple print inside and that's how a function is you have your keyword df your function name print disease and a semicolon and your indentation so whatever follows this indentation is your entire blocked off function you use triple quotes in front at the top of your function this is your function documentation what this means is if you use help with your function name this will be part of your function documentation just like that this specify your parameter this is just specifying that I want the first a string as a parameter just printing a variable sorry default values same as C you can specify your default values sorry same as C plus plus plus C posisional arguments it's in multiple parameters keyword arguments same as what you did for your default values arbitrary arguments same as C just use a star keyword arbitrary arguments just use star star return value just use return and your value this is where some people get surprise you can return more than one value for Python this is what we call unpacking once you see an equal sign more than one value on the left hand side of an equal sign is called unpacking and if you want to do multiple returns this is how you do it same as any other languages you can return one or two it depends on your statement if you want to ignore a return value this is what you do if you get rid of these you get an error because it's expecting three arguments but if you don't really care about the second argument come reported to create another variable for an argument that you're not going to use anyway this is what you do can ignore it using underscore underscore and the question is quite specific so this is called annotation when you annotate your functions with the different keep the value you can annotate your variables your parameters that you pass in as well as your return value so this here your variable name after your colon this is your annotation this part here this is your annotation and for your return value it's annotated using the minus bigger than this is your annotation for your return value what does this do you have your annotation this here string it's your plus string so it's saying that it's expecting 2 variables a plus string variable ham plus string variable that will be read as 8 and then you return a string variable simple and that's it and these are the couple of mutin functions that is found in Python so you can just call these without importing anything here we have already tried a couple of these already and you can try the rest okay next let's look at sorry put I put very short just to give you the description of how to do a file input and output so you have to open same as a scene language just open it open this file 10.md with a write access so I don't have this file in my directory so what this do if it's not available you just create this file so it opens the file writes to the file and closes the file straight away let's have a look what's inside now it creates 10.md and that's it you want to open a file for reading this is what for Python programmers this is what we would recommend to open a file what this do is if open this file as F and you read the data it will close it will close a file for you it reads the data and that's it because it puts it inside a block of codes so this file is open only within this block of codes once it exceeds this block of code it will close a file to read a single line just do an F.read line multiple lines so this here once you have read the first line you read the first line it will now start from the second line onwards you want to go back to the start just do a file.seq this here if you want to be able to do a seek minus 3 you need to open it as a b with a b in front basically as a byte format i'll give you an example so if i want to do this F.seq negative 1 it will give me an error but if i open this file with a b read with a byte format now i can read from the third byte from the back i can also read it as a list basically i'm casting whatever output from the file as a list this here is because i start from the third last so we have 1, 2, 3 characters and that's just a file input output there's more you can explore on yourself next is how to create a module so we have imported modules so how are these modules created in python so what we need to do a module is basically any file that is ending in py we call it a module each script that we write in python we put it as a module it can be considered as a module so let's read this directory create a file called F-I-B-O for Fibonacci dot py and copy and paste this chunk of code inside that file let's do that so inside this here let's create call this dot py bible dot py save it now we have a bible dot py and we have this chunk of code inside now we can import it just like that we have a Fibonacci n and Fibonacci 2 so we define these 2 functions put it inside a file called Fibonot py and now we can use it let's give us the Fibonacci up to 1000 and the Fibonacci up to 100 now are the modules access if you notice this is your file name that's it this is your file name and this is your function name inside your file if you want to run the module from the command line just add this at the end of your file so let's do that let's copy that in Fibonot py put it at the end like so at the end of your file save it now we can run this from the command line let's do that run it from the same directory as your Fibonot py so go to the same directory and let's run Python and pass in aparent 50 this is just a little module search hierarchy so basically it will start searching through to see where you can find this module Fibon this module Fibon we will first search through the directory where you are running your streets then only it will search through your Python path and then only you will search through the default libraries and that's the module okay okay so the next workshop you can definitely try so this year this basically is just for you to create a card deck so you are creating a card deck of a k queen jet 1 to 9 1 to 10 1 to 10 2 to 10 1 to a k queen jet 2 to 10 alright so you can import the collection this year it's just because I saw part of the tutorial so just run that and then you can create a class give it a try create a class that represent a standard 2 card deck sorry that is correct I haven't gone through cards so sorry classes I haven't gone through classes one more last one then you can try the workshop yourself classes yes so classes is very similar to modules it's a difference between class and a module is the same difference as a function as compared to a class in C or Java or any language right we have a class basically that means that you have your variables you have your functions and you have your your references and your instantiation you can instantiate a class you can inherit it the same way you can do any object or the language so how do you define a class same way just do a C, L, A, S class define the keyword followed by the name of your class so in Python for functions we tend to stick with our camel case with the first basically starts with a small letter and for classes we start with a capital letter similarly your 3 triple quotes will be your documentation for your class you can define your variable and you can define your function now you can instantiate a class and say the X is my class and give it I of X simple questions let's try so we have a complex class with a real part and imaginary part and how to initialise this complex class we have our cell real part and imaginary part now we give the real and imaginary like so because it's an object you can treat it the same way as you would an object in any other what this means is that if your counter is 1 it stays as 1 and you can treat the method as you would any method you can pass your method as an argument the next couple just to demonstrate the class as you would any class object or in the language we create a class called dog the kind is canine and this is how you do it for each name you initialise with a name that is passed in and you initialise the treat set of empty list and you create two objects dot A dot B using the class dog and give it the name final and body so as you would any object if the time is canine the object will always be have the same kind and because you pass in your name of the dog each object will have a different name and you can call the method accordingly questions? so with that you have all of that that makes this serves as your reference you can go home and try cut that I will run through the sample for you right now so you can see what it looks like and I'll upload the sample take a look at this so if you have that import collection and you create a class for the deck you initialise the rank to 10 from 2 up to 11 so this is from 2 to 10 and J2K and A We initialise the suits we have 4 suits Spades, Diamonds, Clubs, Hearts then you initialise you create the initialised function so when you initialise this branch that we have a card of ranked suit this is an elbow we divide the length it returns Kekakannya, kaki yang terlalu tinggi dan tinggi Hiten akan menerima kondisi kaki Kekak kaki merupakan diamond 7 Jadi kita hanya membuat kaki yang terlalu tinggi dengan kaki 7 Dan anda ingin membuat kaki yang terlalu tinggi dengan kaki yang terlalu tinggi Jadi kita mempunyai kaki 52 Kita mengambil kaki pertama, kembali kaki yang terakhir Mereka mengambil kaki yang terhubung oleh kaki yang terakhir Oleh itu, memasuk kaki yang terakhir Dari kaki yang terakhir, kita mengambil kaki yang terakhir dalam kaki merupakan Dari kaki yang terakhir, kita mempunyai kaki yang destat Kita membuat kaki yang terakhir Kita memmengewar, sebabkan yg berdasar Sekarang kita membuat kaki yang terakhir Bisa kita cuba esok saja? You don't have to follow exactly these, but they say this is a complete exercise to try at home. Sorry I've run so late. Questions? Let me know if you have any feedback, please. Thank you.