Python : Beginners Guide to Python 3 Programming | PyMinds Programmer | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Python : Beginners Guide to Python 3 Programming

teacher avatar PyMinds Programmer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

56 Lessons (9h 54m)
    • 1. Section-1.1 Introduction

    • 2. Section-1.2 Environment Setup

    • 3. Section-1.3 How We Learn

    • 4. Section-1.4 What We Learn

    • 5. Section-2.1 Introduction

    • 6. Section-2.2 Variables

    • 7. Section-2.3 Hands Dirty

    • 8. Section-2.4 DataTypes Part A

    • 9. Section-2.5 DataTypes Part B

    • 10. Section-2.6 DataTypes Part C

    • 11. Section-2.7 DataTypes Part D

    • 12. Section-2.8 DataTypes Part E

    • 13. Section-2.9 Operators Part A

    • 14. Section-2.10 Operators Part B

    • 15. Section-2.11 Operators Part C

    • 16. Section-2.12 Operators Part D

    • 17. Section-2.13 Operators Part E

    • 18. Section-2.14 Output

    • 19. Section-2.15 Intput

    • 20. Section-2.16 Conditional and Loops - Part A

    • 21. Section-2.17 Conditional and Loops - Part B

    • 22. Section-2.17 Milestone-1

    • 23. Section-2.18 Arrays

    • 24. Section-2.19 String Manipulations

    • 25. Section-2.20 Functions Part A

    • 26. Section-2.21 Functions Part B

    • 27. Section-2.22 Functions Part C

    • 28. Section-2.23 Lists and Tuples

    • 29. Section-2.23 Milestone -- 2

    • 30. Section 2 End

    • 31. Section-3.2 Classes Part A

    • 32. Section-3.3 Classes Part B

    • 33. Section-3.4 Classes Part C

    • 34. Section-3.5 Classes Part D

    • 35. Section-3.6 Inheritance and Polymorphism Part A

    • 36. Section-3.7 Inheritance and Polymorphism Part B

    • 37. Section-3.8 Inheritance and Polymorphism Part C

    • 38. Section-3.9 Inheritance and Polymorphism Part D

    • 39. Section-3.9 Milestone - 3

    • 40. Section-3.10 Abstract Classes and Interfaces

    • 41. Section-3.11 Exceptions Part A

    • 42. Section-3.12 Exceptions Part B

    • 43. Section-3.13 Exceptions Part C

    • 44. Section-3.14 Working with Files Part A

    • 45. Section-3.15 Working with Files Part B

    • 46. Section-3.16 Working with Files Part C

    • 47. Section-3.17 Working with Files Part D

    • 48. Section-3.19 Milestone -- 4

    • 49. Section-3.18 Threads Part - A

    • 50. Section-3.19 Threads Part - B

    • 51. Section-3.20 Threads Part - C

    • 52. Section-3.21 Threads Part - D

    • 53. Section-3.22 Threads Part - E

    • 54. Section-3.23 Sockets

    • 55. Section-3.24 Working with Databases

    • 56. Section-3.24 Milestone -- 5

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Learn how to program in Python 3 and become an expert. This course will help you improve your programming skills by providing assessments at the end of each lecture and also practice python programs for self assessment and become a confident programmer.

This course is also good for college and school students who are interested in learning programming in any language. Python programming is the best bet for them.

After completing this course:

You should be able to confidently write your own python programs with great confidence

Confidently jump is specialized areas of python like Neural Networks, Machine Learning, data Visualization, Web Development etc

Meet Your Teacher

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Section-1.1 Introduction: Did you know Python is the most popular programming language of your 20-20 and it was invented by Guido van Rossum. Python is mainly popular because of ease of use and fast development. Great for quick and easy prototyping, mainly because of simple and readable syntax and has a huge number of support libraries for anything you can imagine. It has very active open source community where you can get answer to virtually any question and troubleshooting issue. It also supports powerful and yet user-friendly data structures and much, much more could simply using procedural or object-oriented style. Its data structures are simple yet powerful, making the coating very compact and easy to understand. It has wide range of MLA math libraries. Python can be used for machine learning and AI development, data visualization, VIP development, and also for scientific and numeric computing, game development and much, much more radius companies like Google, Microsoft, Facebook. We'll use Python in their daily lives. In this course, you will learn basic syntax, control flows, advanced tools, concepts, and hands-on coding. We take each concept, understand the syntax and implemented as Phyton cold. Thereby, we improve our coding skills, right? Coleridge much faster pace and become an expert Python programmer. To support our learning, we have regular assignments and quizzes and summary notes at the end of each section. Thank you and see you soon. 2. Section-1.2 Environment Setup: Hello friends, welcome to this exciting journey on Python programming. So before we proceed with programming, we are actually going to install though, relevant ID for developing our programs. So the best programming ID that we have for Python and spy chang, We can just search for bike jam download. And it is going to take us to the JetBrains, download URL, and you can actually click on the community edition. Well, the Professional Edition is not free, but the community edition as open source and free, free of cost. So I've already downloaded the PyCharm. All I'm going to do now is go to my Downloads and double-click on my ID. So this is going to open up our installation dessert. So in the installation wizard, we just keep clicking Next, we can actually create a 64-bit launcher as well as associate dot PY files, but by John. And we can click Next and we click on install. So the installation process is going to take a while. Until then I'm going to pause the video. Congratulations, the installation is complete. Now all you have to do is click on Run Fei Chang Community Edition check box, and click on finish. So this is going to invoke your buy jam ID for the first time. So we have the PyCharm ID. So I'm getting this Import dialog. If I had any previous installations, if you had any previous installations, you will get this dialog. Otherwise you would actually get a license dialogue which you will have to accept. So in this case, I'm just going to click on the import settings and click okay. So this is going to open up our beautiful colorful buy jam Community Edition. Here you can select two teams. So one is dark color or light. So I'm going to keep it as default and click on Next. Here we can actually install any kind of plug-ins that are required. But for our purpose, we don't need any of these plug-ins. So all I can do is click on Start using Python. This is going to start off by Tom ID. Yes. So we have our BioGRID note. Till now, we have actually not installed Python, we have just installed by job. Okay? Now, when we create, click on Create New Project. And you will see that the PyCharm is trying to find out if there is any interpreter, python interpreter, and it has identified that there is no Python to that. All right, so you can select data by 3.7 or 3.8. I'm going to select Python 3.8 and click Create. So before that I can actually give a project name. So I save my project and I click Create. So what this is going to do is it does actually going to download the Python 3.8, the latest Python 3.8 portion, and it is also going to install this Item 2.8 version. So this is going to take a while. So you can see it is asking for an approval dialogue that has windows approval dialog from Edwin authorization. So I'll have to select yes for that so that it can proceed with installation of Python. So now the Python installation is complete. The next step is the installation of creation of virtual environment. So basically, Phyton has the capability to create virtual environments where you can store all your dependencies and all your settings. So we are going to talk more about which governments as we go forward. So let's wait for the creation of the virtual and drama. So finally, we have our new project. And if you want, you can also see that the PyCharm and Python 3.8 have actually got installed. So you can see Python 3.5.2 and by 20.321 in the latest by job aid issue, community edition are installed. Now. Now that we have installed by chomp, we can actually test our installation. So we are going to create a new Python file. We'll name it as helloworld dot PY. And let's write a single statement, print statement, Hello, Python world. And let's try to execute this. So we go to run and we click on run, select the hello bond. So yes, you can see that Hello Python world got printed out. You can also alternately executed from your harassment. And by the way, you're getting a Windows Defender warning here, you can actually ignore this one. You can say do not show again. 3. Section-1.3 How We Learn: I know that you have understood how to run Python programs and got your hands dirty on the ID. Now, before going into the lectures and actually learning button, that is one last thing that you would have to do, would have to download though, Project, the Learn Python project from this current lecture. Ok, and extracted as I have done here. Okay? And then you will have to open that particular project. So during extraction, you make sure to right-click and say Extract All and don't extracted into learned by them folder. But you can delete this, okay, and then extract okay, that. It's going to take a while because there are large number of files. Okay, now once this is done, all you have to do is click on file and say open, okay, and you go to the location where you have extracted that particular folder. So in my case it is in documents directory. So I go to documents directory and this is the project, okay? And I click OK. And make sure you click on this window. So this is actually going to open the complete Python code that has been used for each of these lectures. Ok, so starting from Section 2.4, you have to Python code, okay? And this is in section two, ok? And similarly for the advanced Python, you have the code in section three as well. Okay? So what you have to do is for each lecture, you open the file. Okay? You create a blank file like I have created here, like lecture 1.01y. Okay, so how do you create that? You just click on that particular lecture folder, new Python file, okay? So you can just create some file here. So let's say I have created a test file. Ok, now, once you have created this file, as you go through the lecture, I request you to do the same thing yourselves, okay, so that you get proper hands on off-field of Bitcoin, okay? And once you have done it and the lecturers completed, then you can click on each of these Biden file, start the assignment files or other files, okay? Like none non-numeric dot p y. And this is nothing but what has been actually taught in your lecture. And you can just revise whenever you wish. Ok, you can just go to I have actually added comments wherever it is required so that it is very clear, okay? And once you are satisfied and one to think that you have understood everything, you can actually go into the assignment that got there are multiple assignments in some, some lectures, but in most of the lectures in Section two, you have only single assignment, but the multiple choices where you can actually test your knowledge. Okay? So for example, for this multiple choice question, you would have entered as 0s. Okay, similarly, you get all your answers for all these, note them down in your note pad. And after you have answered all the questions, you update your answer here. So that is put your answers here. Okay? No comas, no whitespaces. So just delete this particular sentence and the answer. Leave the single quotes and put in your answers here, okay? Some answer, whatever you think is correct, okay? And then what you do is you right-click and then you execute this assignment. So the moment you execute this assignment, it is going to tell you whether you have got the correct answer or not, okay? And if you want to see the answers, you can actually see the answers here, okay? So you can little bit, if you scroll up, you can actually see these answers. So if I copy these answers, okay? If actually copy these answers and don't remember these answers, okay? So and paste it here. And if I execute, you're going to get, Congratulations, you have all the questions. And third correctly, OK, answered all the questions correctly. So this is what you're going to actually get. So, so, so all what you have to do is be honest and go through all these questions and and sew them diligently. And then once you are satisfied with this whole section lecture, if you think there are any doubt, you can revise, you can go through the videos again, okay? And once you have done, you go to the next lecture. So in the next lecture again, you don't open the assignment, you create a blank file. You go along with the video lecture. And wherever you want, you can pause or slow down the lecture, okay? And once you have completed, then you go into that particular python file, C or everything. Try to understand everything, make sure you have not missed anything, and then go into the assignment and so on. Just completed for all your sections, okay, in some of the sections, in your advanced, in your advanced Python, you could have multiple assignments. Like it is not just a multiple question answers, multiple choice answers where you would be asked to actually implement something, okay? And if you are done with the implementation, you can actually scroll down and see the answer, how I have implemented at OK. You can check and see. And also I request you to interact with me as much as possible so that if you are having any doubts, I can actually clarify your doubts than in there. Okay? And at the same time, you could get answers from the other students who are actually following this particular course. Also, after significant learning, we will have milestones. We will have five milestones basically. So after say, datatypes, operators, output, input and conditional statements, you have one milestone, OK, where we are actually going to write an example on a library book management, which basically has books. Fls members would want to reserve these books, okay, kind of a library management software. And then after completing the section two, that is after completing lists and tuples, you would have another milestone where we would implement or modify this code to have additional functionality and use the features that we have discussed after milestone one that is using functions, okay, more of string manipulations, et cetera. So similarly, in section three, we will have milestone three after classes and inheritance. So we are going to use the classes and inheritance concept in exercise three. So the complete code is provided. You can simply execute the code right from here, okay? And you should be able to run the complete example, okay? And then after section three, similarly we have Section four. After working with files, where you will learn how to do exception handling, working with files, how to use abstraction, that is using abstract classes and interfaces. Okay? And then finally you have Milestone five where you would be implementing the database functionality that is connecting to MySQL database and inserting the records that is inserting this members records and book records and actually querying this data and all that stuff. Okay, so it's not just going through these videos and then completing your assignments, you're actually going to write a significant amount of code and you will get hands-on experience. Okay, thank you and see you in the next lecture. Bye. 4. Section-1.4 What We Learn: In this course, we will cover the Python basics including datatypes, operators, input and output, conditional and loop statements, arrays, lists, and tuples. We also cover string manipulation functions and exercises between each of these lectures. As part of advanced Python, we are going to learn classes and objects, object-oriented programming, abstract classes and interfaces handling, working with files. And also Python threads, networking and sockets, database connectivity, data manipulation and exercises. Between each of these lectures. We will have major hands-on exercises after a significant amount of learning. Thank you and see you in the next section. 5. Section-2.1 Introduction: Welcome to this section on Python basics. In this section, are going to get our hands dirty. Deep dive into Python basics and start writing code. In the first lecture of this section, we will discuss on variables, how to execute Python from terminal, how to add comments, and how could compile Python files. Subsequently, we will discuss on datatypes, operators, input, output, conditional and loop statements, arrays, lists, tuples, string manipulations, functions, and of course, exercises in between each of these sections. Thank you. See you in the next lecture. 6. Section-2.2 Variables: Variables are the basic building blocks of any programming language. Let us understand the concept of variables in Python and how it is different from other programming languages. Programming languages like C, C plus, plus, java, etc. Every variable has a corresponding memory location. For example, if you declare a new variable, say a is equal to one, then a new memory location is created and it's value is assigned to one and it is pointing to variable. Okay? Now, if we create another variable, say b is equal to two, then you have a new memory location which is allocated by the program. And its value is set to two and it is pointing to the variable b. All right, now, let's say if I make it as a is equal to B, then what would happen? The value of a would be set from one to two. So what you can see here, you have separate areas for each variable. And each of these variables would have its own values. Say for example, if you have a program, a mathematic program, which has a million 1's and million twos in it. So what would happen? Boolean variables of value 1, million variables of algebra two to be exact, then you would have different locations for each of those variables. A million locations. Pointing to million memory locations, each of value 1 million memory locations, each of value two. Ok, but it is entirely different. It's just the other way around in case of Python. So let's see how it is. In case of Python. In case of Python, you have all the object values basically are stored in a specific location. Say if you have one object value, if you have to, and if you have, let us say a floating 0.1.1, okay? So if your program space, all these variables will have different memory locations. And each of these object values would be tagged to different variables based on its value. Say for example, if x is equal to one, then x would be tagged to this memory location. If zed also is equal to one, then you'd be back to this. And similarly, if y is equal to two, you will have y here, okay? And if w is equal to 1.1, then this would be actually tagged to W. Now, let us say I change the value of y from two to y is equal to three at a later point in time, then what will happen? Then? You would have a new memory location for your program. So this would be three and this would be taken away, and it would be placed here. So this is how it is going to be. And now the two, if this two is not referenced by any variable, then what would happen? Then this would actually eventually be having no tags and it would be garbage collected. So what is garbage collection? Garbage collection is basically cleaning up all the memory locations or releasing all the memory locations which have no tags, no more tags, right? So in this case, let us say, for example, if you have a mathematical program which we have developed in Python, which has a million 1's and million two's, okay? Variables, million variables pointing, having variable value 1, million variables having a value of two, then you would have only two memory locations, objects. And it would be having a million tags and million tags of two. So, which is why the memory management is very, very efficient in case of Python. Whereas in case of other programming languages, you would consume a huge amount of melting. And also the garbage collection is much more easy because all the Python has to do the pythons virtual execution and Broadbent is to check all the memory locations and see if they have any tags. If they have no tax, it can simply clean up and release the memory for the operating system. So this is the main difference between Python and other programming languages. So in the next section, we are going to get our hands dirty. C, u, y. 7. Section-2.3 Hands Dirty: Hi. In this lecture, we are going to understand two things. One is how to write comments and what is the utility of comments. And second is how to compile your Python files and how to work with command line Python from the command line. Okay, so let's open the PyCharm now and create a new project. And Python, Fei Chang. So I click on Create New Project. And I call this learn Python project name. And I make sure we are using 3.8 Python, the latest one, and I click on Create. So this is going to create a virtual environment as well for you, which will take a little bit of time. So I'm going to pause the video to them. So we have the new project created, okay, and it has got its own virtual environment. Now, let us create a folder directory inside this project. We called this as section two. And within this section two, we're going to create a new Python file. Select Python file and dot P Y. Okay? Now let's write some simple Python code. Say we say a is equal to ten, OK? B is equal to 20, and c is equal to a plus b. Okay? And we print C. Okay? So let us run this code. Run second five, and click on comments. Okay, this is actually going to run and provide us with an output of 20. Now, let's understand commits now, why do we need comments? Basically, comments are required for two purposes. One is to understand what is written in the Python code, mainly what is written in the subsequent pieces, subsequent lines of code. So that is one reason why you want to put comments. And second is you want to comment out certain piece of code for debugging or testing purpose. Say for example, I want to commend out here. Ok, so that is, that is the, another purpose of using comments. So there are two types of comments, okay? One is a single line comment, the other is a multi-line comment. So in single line comments, we start the comment with hash, okay? And we say we write the current. In case of multi-line comment. We either use double quotes like this, three double-quotes, okay? And ended with three double-quotes. Or we use three single quotes and ended with three single quotes. So here you can have, this is a multi-line comment and as a line and another line, etcetera here also you can write the same thing. Okay? So and then another line, another line, etcetera. So this is how you actually put it, your comments. Now, these comments will help you in understanding the overall program or subsequent lines of your program. And it also helps you in commenting certain pieces of your working code to see how the program behaves. That is how you debug your program, okay, that is one of the ways of debugging your program or to understand. We will understand debugging as we move forward. Ok, now, how do you, so one way of actually compiling your Python is going to run and execute the rm command, okay, it was trade away, execute your Python code. The, another way to execute is using the terminal, okay? So you can go to view tools and select terminal. Okay? And from here also, you can actually execute, let's say I execute Python C, you get a Python prompt. No, in this prompt also, you can actually test your code. Say, I say e is equal to ten, B is equal to 20, c is equal to a plus b. Ok? And if I print C, C into value is 30 to exit your Python. So this is a great place where you want to execute single lines of code and see how it works, okay? Now, if you want to execute a bunch of lines, the best places to write it in a fight. Okay, now to exit, you just need to say exit bracket, open bracket, close. So this is where you are going to, this is how we are going to exit from the Python, okay? So you can use both. Now, if I want to execute the whole python file, I can say python. First thing I need to do is go to the section two folder. Okay, I can use Tab for autofill. Okay. And clear. Let me clear this and say Phyton, CBO. Mm, and I hit tab. So it is going to auto-complete and enter. So this is another way of executing your Python. Now, if I see there is no binary file that actually got created. That is, the python is compiling this code on the fly and executing it. But sometimes you don't want to share your code, you want to share the binary part of it, just the binary. So what you have to do is you have to say Python, hyphen M, compile all and give you comments file. Ok, so what it does, it compiles your Python file. And what does it return c, it created a new directory under, underscore, underscore BY cache. So you can go into this. And if you see there is a PY C5, you can't actually open this PYT file because it has combined your code and it has created a PYT file. But if you want to execute this, so you could actually share this to the third party, people whom you don't want to share your actual code. So you're going to give a binary compiled code to them. Okay? So you just say python to execute it. Comments.find UIC and it is going to execute your Python code. Okay? So this is, this is the way of actually compiling. So in our case, we need not actually do this compilation step. We can directly executed from here itself, or you can directly executed from here. Okay, So this is what is about compiling. So I'm telling you all this because you get more familiar with Python. You understand how to use Python from the terminal. They're confident in using Python from Europe, from the terminal, from the command prompt, as well as from the ID environment as well. Okay? And in case you have to supply your binary file to another third party, you can actually share it after compiling it so that they can't see your code. In the next section, we're going to define datatypes. See you soon. Thank you. 8. Section-2.4 DataTypes Part A: Hi, in this section, we are going to understand to datatypes, one is none and the other one is a numeric datatype. Within the numeric data type, you have three types. One is int, the next one is float, and the third one is complex. So we're going to look at all these funds. So what is a NoneType? Nonetype is a variable which holds no value. Basically, it is equal into Java's or C, C's null. Ok? So how do you pull setup variable to an NAN value? So just by typing none with end caps, okay? Please remember, you can't put it in small if you put it in smaller to the syntax error. So you're going to get a syntax error. So it has to be with complex, with a capital N, Okay? Now, a NoneType evaluates to false. Actually if you're actually evaluating it, Zynga Boolean expression evaluates to false. Okay, we will understand these expressions in the next sections in the coming lectures. Okay? So I'll just show you how you can test it. So not a okay. Then you have to have an indentation to within this if statement. Okay? So whenever there is an if block, OK, so just remember, you need to put it in a, under an indentation that is, there has to be a space, a proper space. So you will see all this when you're writing complex if statements for loops and all that stuff. But I'm telling you, so you get more familiar. Ok, so a is false or none, okay? So if you print, now, I'm selecting data types one, okay, that is the file that I've created here and I'm executing it. So you can see it says a is false or none. Okay? So if I set this value to ten, so this particular execution will not happen. Ok? This if statement will be false and it will not go inside. Okay, so I'm just putting it back to none. Now, let us see for the numeric data types, okay? The first one is int datatype. So you can set a is equal to minus 32, okay? And print a. And you can also print the type of a. Okay? What is the type of this particular variable? So let's see what comes out. So you can see it is of int type, okay? It's classes, Integer, it's an int object. We will see the types when we get into our classes and all that in the advanced by item. Now, one thing that you need to remember, there are no variants often like short, okay, big int or long, et cetera, in Python. Okay? In Python, you can have as big an integer as you want. There is no limitation. The limitation is the size of your RAM. So there is no problem at all. Okay? So if I type print a right now, it is still an integer. It is not going to show it as long. Okay? So you can see it is still an int and it's values shown here. And another important thing that you need to understand, you don't write like int a is equal to five, like dissent Python. Okay? So in Python you simply specify the variable name and the value. And Python will automatically set the a type of the particular variable, whether it is a built-in data type or whether you have defined a new datatype using classes. Okay, it is automatically going to assign it. So there is no problem with that. Now, the next data type is float. So for the float data type, how do you define float is nothing but decimal. Ok? So you can say a is equal to 1.442, let us say, okay, now if I print a and if I print type of a, so if I execute this, you will see it is float type. Now there is a limit to the length of a float. Okay? Let us see that how much it is. Ok, print. So to find out that you have to import a library, okay? So we will understand these libraries later as we move into the advanced portion. So okay, and you can just say print sys, dot float info dot max. Okay? So this is actually going to give you the max value of a float, which is this value. So I'm going to go into, just put it here. Ok, this is the max value. Okay, so you understood float int. Now, the next type is complex data-type. So what is, how do you represent a complex datatype? It has two components. It has a real component and imaginary component. Okay? So four plus six j. So if I print this C1 complex and also print the type of CBA, let us see what does it give. So you can see it is four plus six j and it is complex. Now, let us say I define another variable, okay? Six plus four j, okay? And if I say S3 is equal to c1 plus c2, okay? So what does it do? It will add the real components and it will read the imaginary competence. It does not want to mix these two, so it will be ten plus ten j, right? I will just print C3 and you'll see the value. So it is ten plus ten j, ok? And of course the type is complex. So you have understood all the three types, int, float and complex. Now, if you want to convert an int to a float, okay, then what would you do? So it is just a type of casting. Okay. If I say F is equal to float, let say I say a is equal to 13, okay? And b is equal to float of a, OK? And print B, and also print type of B, OK. So let's print the type of p as well. So you can see it has 13 and it has become float. Similarly, you can convert, say if a is equal to 13.1, b is equal to into of a. Ok, so let's see what we can now print a, print b, okay? And print type of B. Ok. So let's see. So it is int, so it has just terminated that 0.1, okay? I think even if you put 0.6, it is going to terminate and show it as 13. So 13, okay, it is simply going to remove all your decimal part. So that is the conversion from int to float and float to int. Okay? Now, another thing that you really need to understand this, the number system, ok, you have different number systems. You have binary, okay? And you have octal, okay? And you have hexadecimal. Okay? And of course you have decimal. Decimal is nothing but based and right? Based it. So you don't need to worry about it because everything is based in generally what we are going to do. So binary is nothing but base two, right? So this is base two. And what are the allowed values? 0 or one. Ok. And how do you represent a binary number? And Python, you start with 0 b or 0 capital b, okay? That is how you start the bullet. And octal Oculus base eight. And what are the allowed values? 0 to seven, okay? And you will have 00 or o smaller, OK. You can use any of these o capital or OS Paulo hexadecimal. You have 0 to nine and a to f, right? A2, f. And how do you represent this? O small x or 0, small x, 0, small x or 0, capital X. Ok? So the first letter is always starting with 0. Binary will be b small b, capital B octal is o, hexadecimal is x, OK. And base ten, you don't need to put anything. So if I say binary b, let us see. If I say b is equal to 0, B, OK? And 101, okay? This is how I will represent it. And oh, octa, octal. Okay. In octal, what I do. 0 capital or follow whatever. And I can say 107, okay? And hexadecimal, which I can say 0, x ok, 1-2-3, F, something like this. Okay? And this is how you're actually going to represent all your numbers, okay? Now, you can actually print all these values also. So if I'm trying, if I print this number, let's see what is going to come. Present of B. Ok, and print o, print H, print o, print hx. Okay? Now let us see what is it going to return. So you can see five. So that is two to the power of 0 into one. Ok? Two to the power of 02, to the power one into 0 to the power of two into one. So four plus 15. Similarly, 71 for binary and octal, and then four hexadecimal. So these are the number conversions. This is how you can actually represent and you can change these states as well, okay? Change all these. So for example, if you want to convert a binary into an integer, okay? So what you can see you do is C is equal to, okay, int of okay, SDR. You have to convert this into a string. Okay? So SDR is basically going to convert this binary into a string. Or you can yell binary into a string, B, OK, comma. You can give based in or based in, or this is the default actually, okay? You don't need to pass this base ten as well. And you can say print C. Okay? So this is actually going to convert it into decimal based in, so that's five, okay, so it automatically converted. So in this editor, what you can do is you can hold your control and you can click on int. And it will actually show you how you can initialize C. When you're initializing, you give the value of x and you give the base, okay? Your base could be Basie based in anything. Okay? So you can convert a string from one string to a string to a different base values, okay? Base two or base eight are based in any kind of values. So that is how it works. You can also convert a binary, or in fact a base ten number into binary, octal or hexadecimal. Say, if I have a number 1024, I can just say b is equal to been off, okay? Okay. And then if you have octal, o is equal to OCT of a, OK? And hexadecimal, okay? That is HX. Let us say this is nothing but x of k. You can print all these things and see print B, okay? Percent o and print hx. So you should be able to see them in their representations, in the true representation. So this is binary representation of wonder to fourth, and this is the representation of when the ripple folded in October. And then this is hexadecimal. 9. Section-2.5 DataTypes Part B: Hi. In this section, we're going to talk about a lot of data types. Okay? So we're going to talk about Boolean. We're going to talk about sequences. Within sequences, we're going to talk about the STR, bytes, bytes, array, list, tuple, range, and we're going to talk about sets as well. Sets have set and a frozen set. Okay, don't worry too much. These are very simple data types. So let's start off with Boolean. So a Boolean has two types, only two types of values that is true or false. Please make it a point. The first letter is capital, okay? So you can specify a value like true. Ok, b is equal to false. And if I print a and print B, OK, print type of a. Ok, so let us see what is going to come. So you can see it's not there in the list rate, you can't execute it. So what you had to do for the first time, you go here and you click on Run, and then you select your datatypes, two files. Okay, so now you can see, so it is printing a is true, B is false, and the class or the object type is bool. Okay? So this is a boolean type and also boolean is internally represented. True is represented as one and false is represented as 0. Okay? You can actually see that as well. If I say print, okay, e plus a, e plus a, OK? So if you see this value, so it's going to be two, okay? And print B, okay? Plus b. If I just add b plus b, it is going to be 0. So you see this 0. So now you understood how, what a Boolean is. You can also represent Boolean like let's, for example, x is equal to ten, y is equal to 20, okay? Z is equal to x greater than y, and w is equal to x less than y. Okay? So this is like expression evaluators. Okay? So this is a Boolean evaluator. So let's just print it out and see print z, okay, and print W. So let us see what is going to come out. So it has come out as false, okay? X is less than y, okay? Then this less than, okay, zed, right, does that this x is greater than y, that is, ten is greater than y. We just faults, okay. Ten is greater than 2010 is less than 20. It has come out AS true. Okay, so you can represent it as this one. Now, what is the next one that we have in sequences? Sequences, well, is nothing but. A sequence of elements, ok, and sequence of any type of elements. So the simplest of fishes, STR, SDL is nothing but a string sequence. Ok, so let's look at the string sequence. How do we represent the string sequence? So we say SDR, STR r1 is equal to, say, k strings and prints Hello world. And if I say print STR one, let's see what it gives out for us. It gives out Hello world. And you can also print the type of SDR one. Still one, it is a string back, okay? Now, one very important thing is similar to your comments, where you see here like a multi-line comment. You can also have single line and multiline strings. Ok, let us look at those things which are, these are very important. Say if I say SDR I2 is equal to first thing, you want double-quotes inside your hello world. Okay? So what you can do, you can put this in single quotes and say, hello. This is a valid string because you use single quotes to represent this thing and you added a double quote, but to content and other double quote here, it is going to fail. Ok? So remember that. And if I print this OK, to say hello, double-quotes one. So it is working fine. If you want to put single quotes, you can put these in double-quotes. And put this in single quotes. Put this one single quotes. So this is also fine. That's kind of representation. Okay? No, you want single quotes, double quotes in your particular sentence, then go for multi-line. So how do you do that as T3 is equal to double-quotes, okay? You can represent like this. And this has bought, okay. Okay, so this is fine. So put it SGR three and it's going to work absolutely fine. Okay, so you can see, Let's put in another string in our particular printed out. So it prints it out as a multiline string. Ok, so it is going to maintain all your new lines and everything it's going to get, you can have your double-quotes, you can have your single quartz, anything. Another way of representing it, this SDR four is a good DO. Three single quotes, okay? See your editors or automatically putting it. If I copy this, put it here. It works, okay? Again, say print SDR four, and it is going to print it to some multiline similar to the previous one, okay. So it's pretty simple. Ok, now let us look at some interesting string operations. Okay, so let's create another string. Str five is equal to, okay? This is Hello, Python string, some random string. Okay? So now if you want to find the length of the string, so what do you use? You use the len function, len SDR five. So land can be used for various other objects as well. So we understand that as we go. So the length of the string is 29. Okay? Now, the second thing is very interesting thing is the slicing. Ok? So I'll show you what a string slicing, slicing. So if I want to print only the first character, ok, so that is SDR five. Is it STL five? Yes. Sdl R5, 0. Okay, so this is going to print the first character that is t. Ok. So the indexing starts with 0, ok, 0228. So since the length is 290228, now if I want to print leaving the first letter or rest of all the letters, then what I do, just say one colon, okay? So it's going to print starting from h, it is going to print everything. So you can see here, which is Hello Python string, okay, here's is a Hello Python string. Now. So it is basically starting with the index one, age, and then it is going to the end because after colon you have not specified editing. But let us say I specify eight. Okay, so what is going to print? It is going to start with one and ended seven. That is, it's going to exclude this. Ok. So if you see now, execute this. So his is ok, that is, 0 is excluded, one is included, 1234567. Okay. So it has added a space as well. Let us yes, you can see it has put in space as well. That is one colon eight means it will include the element at one and it will print til seven. Ok, that's going to exclude this eight. So if I put an S, So what was the length? Length was 29. Rate. If I put it as one colon 29, it is going to printer string complete til the end of the string again because it is going to go from one till index 28. So the G is nothing but your index 28. Ok. Another interesting thing is you can put this as minus one as well, so it is going to give you from backside. So what was the last character? So g. So you got minus one. This is string slicing, very simple and very easy to pick up the string based on the indexes, okay? Pick up a sub string based on the index. It is very simple. The sleep same slicing applies to various other elements also. And that we are going to see as we go ahead. Okay, now, there are some more operations which are very interesting. So let us look at that. X is equal to STL five dot c. You can say capitalize. So if you think capitalize, it's going to capitalize the first element of this guy, okay? That is this d. Now if I print this print of print x, so let us see what it is going to print. It's going to make this capital ok. Now you want to make everything upper or ok, let's go one by one. So STR phi dot K is folded. Okay? What does case fold? It converts the string into lowercase. Okay? So if I just put this as T, and if I put this as h, okay? And if I print this, x is equal to this and print x. So it is going to give, so it is going to make, Although let us smart, ok. Similarly, you can do to upper to lower ESA pore is law that a huge number of such methods which you can simply go through here. For example, centre. Centre is nothing but it is going to add whitespace at the beginning and the end of the string and center the string. Ok, so basically Python has so many methods which are very useful. And they are just went for the developer to make the life simple for the developer. Okay, so you have C, Eosin is lower, is pneumonic if all the elements of the string, characters of the string not numeric than it does. This is going to return true is space if everything in this particular characteristic-based drew, OK, so 0s above. So you have many such methods, okay? You can also use split, which is very important. You can split this based on the whitespace. It's going to return you an array. So we'll talk about that is as we move. So if you say, if I say split and based on a whitespace, Okay, so what it's going to do, it's going to convert each of these elements into eager. It will return an ad a, and each of these would be sub-elements, okay, of that array. So if I said brand, so it's basically going to return an array. So we're going to talk about that ease and lists. Lists basically. 10. Section-2.6 DataTypes Part C: Now what is the next step? The next type is bytes. Bytes is nothing but it is an array of byte elements. Okay, byte can have, so there is no bite type message, but I'm just telling you bite can have between 0 to 256 values. Okay? So what I can do is LM is equal to, it is an eddy of elements with 0256. Ok, so sorry, 0 to 2550 to 255 and you can have 0 to 2551211, okay? And then what I can say l m is equal to bytes. And I'm just going to reassign, okay? And if I print this lm, let's see, and also print the type. Okay, let's see. So here you have, so this is the representation of the bytes, okay? And this is of type bites class, okay? Now, if you want to print the 0th element of the byte, so you can just put it in a square braces. And if I put in this, so it's going to print the zero'th element. So the indexing, please remember indexing and Biden as in C Java and C plus plus is 0, okay? It starts from the first element, index is 0, the next element is 123. Okay? And I can also find the length of this eddy, okay? If I say I want to know the length, I can just, or lenders NOT available in bytes. Okay? So how you have to find the length? You have to say Len, okay? It's not like Java where you have the length property. So you have for the lenses fault, you have to use a Leanne, okay? Now, in the White City, you can't actually modify these elements in this bytes. So if I save by 0 is equal to 255, okay? And if I execute, it will not let you. Ok, it does not supported, assignment is not supported. And other thing, if I make this 256, let us see and comment this out. Does it allow the value of to 56? It does not allow, right? It has exited with exit code one. So it can have only values between 0 to 255. Remember that? That is important to know, okay? So byte is, so basically bite is not modifiable, okay? But bytes at a which is same as byte is modifiable. So let us create that. Okay? So LM1 is equal to, again create another 16125250, sorry, to 54. Okay? And then we have M1 is equal two bytes array autofill S come, okay? Lm1. Okay? And then if I print this element, print type of LM1, typeof LM1. Okay, so this should be bites Eddy. So you can see it is of type bites eddie. Ok. And also I can set the value that is LM1 of 0 is equal to 254, okay? And if I print, print M1 of 0, okay, interests curators to 54, okay? Now if I make this as 256, it should fail because byte value cannot hold this, just failing, okay? It can be only between a range of 0.250 x means up to 255. That's it. Ok. So you can even set it back. So basically what's the difference between array and by day, they're exactly the same. It's just that you can modify the byte array, but you cannot modify the bytes. And you can also apply the similar kind of slicing operations on bytes, byte array. So how do you do that? So you can just say I want to find the length of the byte array. So you specify in them and a one. So let's print this. So you get four, where you do get fourth, because you have 0123. There are 1-2-3-4-5, In fact, four-elevenths. Ok. Now you want to get though, you want to do some kind of slicing. So print one, okay? And you can say one colon two. So it's one colon three, let us say. So what? It's going to return one N2, only the first two elements. Okay? You can print this out and see here. Ok, so by today, justice up to a sub-element software industries. 11. Section-2.7 DataTypes Part D: Now, next is in the list is a list of horse. So how do you define a list? A list is nothing but you can say L is equal to like an array. Ok? You can have any type of values or a combination of, I can have float, okay? I can have string. Okay? And like this, I can have any type. Okay? Now if I print this, print L, Okay, and print type of l. Okay, let's see what it is going to print. So it's going to print out this list values and the objectives of type list, okay? And another important thing is you can modify the values. So L of 0 is equal to jamie, OK. And now if I print L, Let's see what happens to the 0th element and one should actually convert to Jamie. Yes, one has actually got converted to Jamie, which means you can actually change the values of these individual elements also. And you can also read through, okay, this is the most important thing about all these elements, okay? All these types. So you can actually, I read through them. So how do I treat to them for LI, let's say in L and print LI. So single statement. So this is a for loop which is going to pick up each element from L and printed out, store it in a lie and printed out. Okay? So you can see here. So it has printed out Jamie, 3.41. Okay, Mary Jo, it has printed out all of these elements and the same is applicable for all these. Okay, you can use this particular file statement. There's in-class for all the types of sequences. Okay? Now let's look at some important operations. Of course, you can do the slicing same as your string. Slicing is very important when it comes to list. So I could just say slice starting from two. And if I print this, so it's going to print from here, 01 is going to be out and from two to n, okay? And all of the slicing operations, of course, okay, now there are some more really important things when it comes to list, okay, listers modifiable. So what you can do, you can say L dot. Ok, so let's remove this print statement and we'll say l dot BOP. Okay? First. And you can give an index, say for a given index of two, ok? And I print l. So what happens now? So it is basically going to remove 012. It's going to pop this out, OK. 1.4. So let's see. So you can see her, Jamie, three, Maddie, Georgia 1.4 has gone. It does spot it out. Okay. And what else you can do? And dot insert, insert. You can insert at this thing at a position. Okay? I insert here, say 1.3 at position two. Ok, so let us see what's going to happen. So 012 at 1, at position two. So indexing starts from 0, right? 012 at position two, you're actually going to get this ok. So it can pop out, you can insert and you can append also. So happened, okay. And dot append, What can you append? Append 123, let's say. And CERT C, you get 123. So this is how you can actually update your array, okay? There are many other infact list, not an array list, ok? And there are many other operations which are very interesting and which are very useful for the data block. You can just introspect them and by clicking on L dot and you can actually see you can also use remove. You can also use clear. So if I use clear, it is going to clear your complete array. So it's going to become blank, okay? All the elements in the array will be removed. Okay, as per your requirement, try your best to use all these methods and start off writing your own code, okay? So you want a clear everything, you don't want to remove each element I iterate through there already. So ready-made methods for most of your operations. Okay, tuple is same as list. It's just that you can't modify it. So instead of using square braces, are going to use the this places, okay? And these kinds of places, now not the curly ones, the other ones. Okay? So how do you put in a tuple? So three, you can also have different objects in this. Okay? So yes, whatever. And you can do slicing, you can do any kind of things. You can also print the zero'th element. It's not a problem. Okay? See how it prints out. It has been to doubt one, but you cannot actually change the values. Otherwise it is just the same as your list. So if I put something here, it is actually going to exit. Okay? So i cannot change the value. Tuple doesn't support item assignment. So that is one thing that you have to remember. Okay? So, so this is done. Now what is the next data element? Next data element is actually a range. So this range object is basically used for, you'll basically used for your, for loops, okay? Represents, it basically represents a sequence of numbers. Ok, so let us see how we can do it. So I can say r is equal to range ten. Okay? And then what do I say for i? In our print? I, let us say, if I do this, I need to put a colon here. You should not forget four mod readability. I can put it like this, okay, simple. And if you see what does it going to print said chord, we have an exit code here. Tuple soap doesn't support the assignment properties, so the government decided, okay, now let us see to happen. Yeah, so it has printed out from 0 to nine, okay? So the range is basically used for going through four loop. Now, another important thing about ranges. You can also set the start, end and the step, okay? Say if the start is 510 and step is to, let us say, okay, make this fourth, don't make it easy. So it will get become, become 46810. And if I copy the same chord, put it here. And if I execute this, it does C. So you can see 1468. Ok, so that is how the range actually works. So it starts from four. Okay. Strange. Why is it printing one? So probably from a different statement. So let's put it some, something odd here. Don't make it clear. Ok, so if I execute now, so you can see it is only printing 468 and it's excluding the ten. Okay. So similar to your distinct that means it starts from four and it excludes the debt, okay? And you can use that in a for loop. So that is the basic advantage of range. Okay? Now, the final set, the final sequences set, okay? You have two types of sets. That is, you have set and frozen set. Okay? So let's look into these two aswell. So sets are same as your distinct, your lists, but it is slightly different in that it will not keep non-unique values. So if it, and it will not maintain the sequence ok, in case of range, in case of list, it is going to be deemed a sequence, but in case of set, it is not going to maintain the sequence. Ok? So I am just, so here, you have to use curly braces on the flower braces to actually put in. So 102030. And if I say 5040, okay, so, and I put another ten, let us say, okay, and I put in this, okay. And I put int type professor. So okay, and let us see what it gives. So it is a set type and you see. One of the ten has actually gone because it's a duplicate element. And the second thing that is, that is there is it has not maintaining the sequence, OK, your sequence is totally offset. It is, there is nothing like sequence in here. And if I try to access using an element, it does not allow, it will fail if I played two axis C, there is no support for accessing truer index. Okay? So how do you access a set deliberate element in set? You have to use for loop, okay, for S i in S, Okay? Print. Yes. So that's it. So if I comment this out, see, it has given me 401050. These elements, all these elements have been given over here. Okay? I can also change the value of a set. Okay? So how do I change the? And of course you can also do the slicing, all those slicing operators that you have done before. You can do that. Okay? And so if I say print Es of 0 colon two, let us see the slicing works out. I will just remove this comments. Yes, no, it does not work out. So you can't do any slicing ok. Because of course, because you cannot access anything from an index. So slicing is also not possible from here. That is one thing, okay? You can also update a set. So how do you update a set? You can simply add the elements, add additional elements to a set. You can just say 0500 and you can print s. So if you see for print deaths, say this, adding these elements fail. Okay? You can also convert a set to a list or list to a set, okay? That is also possible. So you can say lst list, and then you can put in s, s, Okay? And then print type and NST. Okay? And if you see now, ok, so it is a list type now. So once it is a list, you can actually change the locations, change whatever values you want to change. That's it. So you can also remove an element from a set. So that is also possible. Say if you want to remove a 500 element 500, then S dot remove 500. And then you can actually print, print this. Ok. So let us just check this one. Let's comment this out. So you have, it has removed that particular element, 500 element, okay? You updated 500 and it has removed that 500. So you can put it in another file. Print here, print this you want, and you can see what is the 400 element you're fired and inventors removed. That's it. So now we have completed all the data types so that as sequences, we have completed sets, okay, which have intuited frozen sets, etcetera. So what are the next things that we are going to look at? We are going to look at mappings. So that is the final datatype. Okay, thank you and see you in the next course, next lecture. 12. Section-2.8 DataTypes Part E: So the final datatype, the standard datatype isn't mappings, okay? Mappings that nothing but key-value pairs. So basically, how do you define the mapping? So m is equal to, it is going to be opening with the flow or braces and followed by key colon value. Okay? So this is how it is going to be. So if I'm going to create another key and you have another value, okay? So if I print this, print type and print M. So you can see, sorry, so this is a different one. So what I have to do now to say Plum Run, I select my data type three. Okay, so you can see here, does it take to object, it's a dictionary object, okay? And it is having these values. So I can in fact add some more values to this. So I can say m 15 is equal to something else. Okay? And if I execute this, say get a keeper. So it's very easy to add Kibera values into this. You can also modify the existing keeper. Okay? So this is a very important object. So instead of just portrait as Jim, And if you see what is going to happen. So it has become 12, has become Jamie now instead of Rob, ok. So you can basically store key value pairs in this and you will see how to iterate through all these things in operators. I iterating through your dictionary objects. So basically lists and dictionary objects are very, very important to that list and mappings. And you should understand them and you should understand how efficiently operate upon them. And that we're going to go through in each of the tutorials that we are going to create for each of these subjects. See you in the next section. In the next section, we're going to talk about operators, vacuum. 13. Section-2.9 Operators Part A: Hey, let us look at operators in this lecture. So what is an operator? Operator is nothing but a symbol that acts on one or more operands. Ok, so let us say z is equal to a plus b. So your operator is plus, and the operands are a and B. Okay? So let us look at different kinds of operators. So we have a domestic operators, assignment operators, unitary operators, relational operators, logical operators, Boolean operators, bitwise membership and identity operators. Ok, now let us look at the arithmetic operators. So arithmetic operators have simple and straightforward there basically addition, subtraction, multiplication, division, modulus, popover and integer division. So let's say a is equal to five, b is equal to ten, okay? So c is equal to a plus B. So if I print C now, so I'm going to run it again from here. R1 and operators. So it has come to 15. So operators a plus 5x plus 1015, okay? Now I do a subtraction, okay? C is equal to b minus a. So it should return us fight, okay? So it is a subtraction operator that is ten minus five is equal to five. Now multiplication operator C is equal to a into b. So that is five into ten. So that is going to be 5050. Now, let's get the modulus. Ok? So let us say B is 11. Just to show you the value of modulus, which is, which has to come as non-zero. So what we'll see is a conto, okay, be percentage a. Okay. So what will happen, fighters ten and you should get a reminder of one which is stored in c. Okay? So that is modulus straightforward. Everything is really straightforward. Now, another is power operator. So that is a or I can say B star, star a. That is what? Basically, if I put it in comments, this will be e to the power of a, b to the power of a. So that will be basically 11 to the power of five. So it will be a huge number, okay? 1-6, 1051, okay? And finally your integer division. Integer division is, it is going to divide them as integers. Ok, so let us see. C is equal to b, sorry, b divided by a. So what should you get? You should get to write not to 0.1 to 0.2 or 2.2 is division, okay? So this is division we have missed as one. So this is division you are getting it as well as a decimal. Now, if I say c is equal to b slash slash a. So I'm just going to get it as to attest to because it is a integer division. Okay? So these are all your automatic operators. Ok? Now, the next one is assignment operator. So in the assignment operator, what is happening? Basically we are going to assign a value to a variable that is on the right side using one of these operators. Okay? So again, let us say a is equal to five and b is equal to 11. Okay? And let us try all the assignment operators here. And what are the operators that we have to try out for assignment? Let's keep them here so we don't miss anything. I put them in comments. Now we have a is equal to B. Ok? So this is an equal to operator where the value of b is assigned to the value of a. So print, a printer, does it that you're going to get the value of a should be equal to 11, right? Because it has been set to this value. Ok, now, what is the next one? Next one is a plus is equal to b. That means this is nothing but a is equal to E plus P, okay? So, which is nothing but, need to put it in as a comment, which is nothing but five plus LeBron, right? And that should be equal to 16. So let us see. So 16, okay? Now minus, OK, so a minus a equals b. So the, which is nothing but E is equal to a minus b, okay? That is five minus 11, which is nothing but minus six. Minus six. So it's very simple. Okay? And the next operators into, so a is equal to a into b, that is five into 1011. That would be 555 into 11 would become 55. Okay? Now, divided by, is equal to OK. So this is nothing but is equal to. These are all very straightforward, okay? You don't need to even worry about them. So phi divided by 11 by five divided by 11. So whatever you are going to get 4.5.45, sorry, 0.45, and then you have percentage, the modulus. Modulus is nothing but a modulus b is equal to e. So we will just place it in fact to just see b. And this is a, this is a. Ok? So this will be what? So b modulus e, right? That paints Levin modulus of five. So which would be equal to phi two is ten. And there should be a reminder of one, right? So let us see if the remainder comes out as one for b. We are going to print the b value here. Yes, it is coming out this one, right? And then you have an integer division, integer division. So this will be equal to nothing but integer division that is 11 divided by, so this will be b, this will be a, ok. And this will be 11 divided by this, which is nothing but two. Right? So this is two operation. So we have completed all the assignment operators. So assignment operators is nothing but you are performing an operation and that value of that particular operation is being assigned to certain variable, which is maintained under a right side of the expression, okay? 14. Section-2.10 Operators Part B: Okay, now let us look at two operators, that is unity and relational operators. Ok, let us put them back here. And let's see what each of these are. Unitary operator is pretty straightforward. It's just a negation, okay? So that means, let's say c is equal to minus B. That means you have negated the value of b instead of 11, it is going to be minus 11. So if I print the value of c, it is going to become negative. So let us see that c is equal to minus b. And let me just take these values again all here. Okay? Reinitialized a and B, so you get minus 11. Okay? Now, let's look at it. It's as simple and straightforward, just a negation operator. Now let's look at relational operator. Now, relational operators are used for combating values. Okay? So comparing whether they are greater than, greater than, equal to, less than, less than equal to, or whether they are equal to or not equal to. Ok, so those are the comparisons that you actually do here. So if I say c is equal to, so C is equal to, you can say a greater than b, okay? And print c. So basically, we are actually trying to check the condition whether a is greater than b, that is five is greater than 11, which is not the case. So if you execute this, it's going to return to as false. Similarly, you can also check for greater than or equal to. Is phi greater than or equal to 11? It's neither greater than or equal to. So again, you're going to get it as false. Ok? And similarly for less than, so if I say less than five is less than 115 is less than 11, which just correct. And five is less than or equal to true. This is also going to be correct, right? And the final 1is equal to a naught equal to, okay? So if you want to check the equal two, you try to do equal to, equal to, not equal to OK. It should be W equal to. Please don't forget about that. And if I execute this, it is going to return us false. But if I put this as five, and if you tried to execute it, yes, they're both equal. So you're getting true, right? The value of these two are equal. I can also say that x is equal to an array, okay? 12341234 something and y is equal to the same thing, 1234. And if I check for x equal to, equal to y, okay? That is, if I say z is equal to x, equal to, equal to y, okay? And I print zed this time. So it should be equal true because the value of these two are same. Okay? So basically it's going to check for the object value. So these are two lists and list values are seen so equal to working and just the opposite to that, this naught equal to, okay? And if I make this as something else, 345, so that their values are not equal, you'll see that it is true. That means these two are not equal. So that is why it is that this become as true. Okay? It's that simple. 15. Section-2.11 Operators Part C: Okay, now let us look at the next set of operators, that is logical. Boolean operators. Logical and Boolean operators are basically the same. They are and or, or not. Basically, these are the only operators that we have for both. It's just that you can apply them to both ADR numeric operants or two Boolean operand. That's the only difference. Okay, so let us again take out values. That is, a is equal to five and b is equal to 11, okay? C is equal to a and okay, it should be all in small e and b, okay? And print C. Okay, so let me just print the value also of what it evaluates to. Okay? So you need to put STR when you're evaluating two basic types. Ok? So that is a just printing the value of a as Boolean and given a value of five. Okay? So what does it return? It returns true, okay? So that is not see as a is equal to five. Just evaluating it. I'll just tell you why I am evaluating it. So this is the case, okay? Now, this what this AND operator stasis. If the value of a is false, it returns x, it basically returns you're a itself, okay? Otherwise, it's going to return the value of b. So that's why you got, Since a is true, you got the value of 11, that is the value of b, okay? And if I say Not, now, why is this Boolean true? So any value other than 00 will be false. Any value negative, positive other than 0 will be true, okay, in Python. So please make, make it a point. So even if I say, even if I print minus ten, okay? Sorry, this will be r, okay? Even if I print it as minus ten. So let us just see. Minus ten is also true, okay? And if I print 0, then it's going to be false. So then it's going to be false, which means any value other than 0 is always taken as true in Python. Okay? Now, in this case of all, what is it returning? It is returning a value of five. Because if a is false, it is going to return the value of b. Otherwise, it is going to return the value of E itself. So that's why big sins is true. It has written the value of a itself. Okay? And then finally, you can use the NOT operator. So what does not say? Not as a unity operator, okay? Not means if the value of b is false, okay? It will return just the opposite, true, okay? It's just a negation operator, just like your negation operator. So this will always be false, right? Because b is not 0, B is 11. So this will return false, opposite of true, okay? Now, if I make B as 0, obviously, so this will become two, right? Because false, not false will become true. That's it. It is that simple. And then on the top. 16. Section-2.12 Operators Part D: So the next set of operators is the bitwise operator. So let's look at the bitwise operators. So bitwise operators basically act on the byte level, ok? The bit-level basically. So even if you supply an integer or you, if you supply a binary, it is going to convert that particular number into a binary system and it is going to operate at the byte level. So that is why it is called as a bit-level operator. No, Dirac saw 1-2-3, 4-5-6 operators in the bit-level operators. So the first one is nothing but bit wise compliment operator. The next one is and, okay, or x4 and the left shift and right shift operators. Ok, now let us look at the bitwise complement operator. Compliment operator is nothing but it just makes it opposite. Okay? So this operator gives the complement of any specific number. Say for example, if you say x is equal to ten, okay? So which in binary representation, as you know, is 00001010, okay? Now the delta of one, so that is tilda of x, okay? Is, let's just print this. So the bitwise operator, okay? And if you print this, it is going to return as minus 11. Why it returned minus 11? Because it is just going to convert it into this and 0101, okay? Just the opposite of it. That's it. It's that simple, okay? And now you have an operator. And operator, let us take two numbers. Let us say x is equal to ten and y is equal to 11. Okay? And I just comment, put in comments here. And if you see it as 00001010, okay? And this is nothing but 00001011, okay? Now x and person, why that is and percent y will be equal to what? This will be equal to. So, and if both of them have to be true in B, so which is not the case, right? It is 0000101, sorry, 101000001010. So this should be or and a and B. Ok, let's print this value. Okay? If I print this value. Oh, it's going to return to b as ten. Okay, so two to the 02 to the bottom one and plus two to the power of three. So eight plus two, okay? So that is equal to ten, which is also very simple and straightforward. Now we have our operator. So in case of or operator, what it is going to be, it's going to be odd a pipe. And why? Of course. And either of them can be true. Okay? So these are all four zeros. This is correct. This is 0, and this is also going to be one. Okay? So that means this has to return us lemon, right? Let us see. So it has returned us 11 because this will be one plus two is 33 plus 82 to the power of 32, oneness 11. Ok? So that's simple and you have odd operators and so is over the czar operator. Czar operator is by putting gap that a shift six. Okay? So czar operator will be what? So only if they are opposites, it is going to be true, okay? So 11, so all these are zeros. This is phi1. 11 also will become 000 is 01 wonders again, 001 is one. Okay? So this should return us to a value of two. That is the CSAT operator, sorry, value of one because two to the power of 0 into one. So that this value of one. Now, so we have covered all these operators. It's pretty simple and straightforward. Now, let us look at the left shift and right shift operators. They are also pretty simple. So what do you do with x? Say, for example, x is equal to this. Ok? Now, let me put these two guys over here again. Okay? And if I say x, x, the first one is left shift to, okay? So everything will be shifted to the left and the left-most two will be converted to zeros. Okay? So what I can do, I can take this same number, put it over here, okay? Add two zeros, and it removed two zeros, okay? And put it back here. So this is what it is going to be for left shift for this. Ok, so what is the value for this? And let us see. So we say print x, left shift to okay? So C, So you've got 40, right? So this is total of 0 to 41 to the power of two to the power of three, to eight, to the fourth, two to the power of five. So it's going to come up with 40, okay? Now, similarly, your right shift. So what is going to happen to the right shift? You're going to add zeros at the extreme. So let's take this guy again and be removed two here. Okay? We add two here and we say 1234. That's it. So this is your number. So what is the right shift operator? Y? Greater than, greater than. So it should come out to two, right? So it does come up too. So it's that simple. So bitwise operators are also done. 17. Section-2.13 Operators Part E: So the next 22 set of operators are identity operators and membership operators. Let us look at each of these. These are very useful operators actually. So I didn't membership and identity operator. So one is E in and the complement of a deposit of it that is not an, okay. So let us say you have a list or array or any kind of tuples said, etcetera. Ok, so 1234, and you have some object here. Okay? So what you can do is you can print okay, one in. Okay, so it's going to return you true. Okay? So let me forward to put in a comma here. And if you execute this and see, It's going to return me true because one is part of this. Okay? And if I say ten knot and say, for example, because ten is certainly not dead within this, right? So it is again going to return us to, okay, and basically where do you use this in? If you remember, we used it in, so a, i in a, in a for loop, right? And we just said print a. Okay? This is where we have actually used in, in state, in operator. So if I execute this, so you can get all these values, whatever values are there in your, you're going to, it's going to print all these things. Ok? So this is basically your membership operator. It is very simple. You just going to check if a particular element as they are in a particular sequence, okay? And it is also going to work for a string if you see string, okay? This is good. Take, let us say, ok, print Good in steel. So it should return us through. Death returned, true. Okay. If I put it as something else, if I put it as bad, let us say bad is not part of the sentence. So it should return us false. Okay, so it's so powerful, ok? It's very simple for you to find out if a particular substring is there or a sub-element is there in the sequences. So all these can be applied to all your sequences. Okay? Now let's look at the identity operator. So this is also very interesting operator. So let us say a is equal to 23, okay? B also is equal to 23, okay? If I print the ID of a, ID of a is nothing but your memory location, print Id of b. Ok. So as we discussed in the variable section, since both are 23, they should actually be pointing to the same thing. Okay? See, they are actually pointing to the same memory location. So this is also pointing to the same memory location. So this is a memory location. So bys 0s or ease naught is basically going to check if they are actually pointing to the same memory location. So if I say print a is b, okay? Then it is going to return to me true because they are both actually pointing to the same memory location. However, if you have a user defined object or more complex object, not just these integers are user-defined objects into say, ill as a list. Okay? So 1234, okay? And I have another m, which is also, which is also having the same value of this, okay? And if I try to print a lend MBO and let em, okay? And if I check Ls equal to m. So let's see what is, what is it going to return to us? So it'll return false because these two are having different memory locations. Even though their values are same, it is going to actually have different memory locations. So ESS actually checking the ID values of these two, whether they are belonging to the same memory location, okay, if they are the same objects or not, or if they are the different objects. Okay, different instances of objects. And if you want to check for the value, as I told you before, you'll have to use equal to, equal to, in which case you're going to get us through. So this is similar to the referencing, okay, references. Are these L and M referencing to the same memory locations or different memory locations? This is what this is going to determine. Okay? Whereas this is going to determine the value r. Does l and m have the same memory, same value. That is what it's going to check. Ok? And the exact opposite of it is, is not, okay. So which is going to become true because these two, it is going to check if they are not, they're not the same objects. So that's it. So it is that simple. So this is the end of our lectures on operators. We have discussed all these operators, and in the next section, we're going to talk about the input output. See you in the next lecture. Bye. 18. Section-2.14 Output: So let's look at the output statements. The simplest offered this. Let's say you wanted to print a string. So this is going to actually break the Hello World string. So we will have to run it from here. Sorry. Print, run and input, output. Ok, so it's returning an output string. So another thing that you can do is you can add some escape character status, okay? So I could say slash en slash and is nothing but your new light, okay? And you could also use slash t, which is a dab space. Okay? So if I execute this, so you can see that as a new line, and that is a damped space as well. So like this, you can actually escape your characters. Of course, you can also render multiline string. So which is, which is really useful, okay? This is string, line, there line. Okay? And this is actually going to preserve all your escape characters. Okay? That is a new lines tabs everything. So you can see here, this is a line, this is a new line. So you're going to get all the characters, all the tabs, everything here. So next level of complexity is comma separated. Okay? So let's say you have a is equal to ten, b equal to 20, and you want to print OK value of e, okay? Comma a. And you can put another comma and value of B. Value of B, comma B. So you have just separated the whole thing by commas. You can put an equal to here also. So this is another way of actually printing lines. So you can see here, value of a is equal to ten, so comma a and the value of b is equal to 20. Ok? So it is going to preserve all your spaces, lines, everything here. So if I remove the space here and we execute it, so it's going to main Dana space. Okay? So value of a is equal to comma, a comma and value of b is equal to this. Ok? So I can actually remove the space. So if you see here, yeah. So value of a is equal to this, value of b is equal to this. So I can put one space here. So comma would automatically put a default space. Okay? So that's the advantage. So I don't put a space here because the coal mine, it's already going to put one space for me here. Okay, is equal to this and B is equal to 20. So it looks good as well now. Okay. Now there is another way of printing. You can use separator actually. So you can see here, you can use sep and end as well TO, Okay, so how do you put it? So this ok, so let us put in some string. This is a string one, comma, this is string two. Okay? And Sep is equal to, I'll put an S colon. Okay, let's see how this prints out. Okay, I have put in strings and I have put in a separator S colon. Okay? So let's see. So you can see this a string, one colon, that's a string too. So you can have different separators for various values that you are actually passing in, okay? And let us say, let us use the end as well. So in this, so, and I can actually use, and also so n does by default new line, okay? I can put in a tab slash p as end, okay, instead of slash. And so what is going to happen if I print another statement, okay? And this is string one, string, two, string three, string for, okay? And if I print this one, is going to put everything in a single line. And it's going to put an S slash d, that is a tabbed statement here. So this is another very useful way of printing your statements. And finally, there is, and there are some more. Okay, so now the next printing statement, this print statement is using percentage i, percentage f, percentage S, and percentage C. Okay, So let us see how we can use it. Percentage i is nothing but integer, postage, office float, percentage as a string, person did C is character. Ok? So what I can say, I again say this is a float, okay? And percentage I. Okay, I can put this in some kind of braces. Okay? And this is string, okay? This let us call it as this is int, okay? Percentage i, and this is float. Okay? I use some flour braces here. And I say percentage f, Okay? And this is string and percentage s, Okay? And coma. What I can do here is put in a percentage, okay? Specify all the variables here. Okay? So I can say it is first as integer. So 12.4421 is float and string is Tommy, let's say. Okay, so let's print this one and see. So why do we have an adder here? What is the error that we are getting hurt? Syntax, cetera, person ditch as string, percentage S. Or probably don't need a comma here. Okay, so that's it. Yeah, our neither comma actually. So if I execute this, so you can see, let's remove these ones. Okay? So let's comment this out for more clarity. Okay? And if you see here, okay, so this is int 12 C. It has gone beautifully in square braces and float 1.4.4, do and string. Guess this. Okay? And you want a position for your distinct say you can say 0.2. So 0.2 means only two decimals will becoming and for your float, say 1.41, okay? And then it further for your string, you can actually say, but the ditch 20 ds. So what it will do, it will put them there. Spaces of 20 here, okay? And if you put in minus 20 here, so it will put a trailing space of 20 character AND spaces here. Trailing space of 20 over here, okay? And your flower braces. So this is another useful way of actually printing your characters. So you can print it in a very descriptive way, okay? And then you can actually use different variables here in this place. And you will get proper descriptive way of bringing your outputs, program output, ok. Now, there is another thing that you can do, okay? So f SDR, that is formatting string, okay? How do you format a string? So you can put it like this. Okay? This is a hint. Here, we don't have any, and you can put in ads like this. And this is a float, okay? Like this. And this is one, and this is string, okay? And you can put it as two, okay? And you can use the function format, okay? And you can give certain variable values here. Say, let us say n one is equal to ten, okay? And du is equal to 1.41 for 23 is equal to N3 is equal to Tommy Lee Jones literacy. Okay? So you can just put all these values here and one comma, two comma three. And if you, and you can actually formatted by specifying N1, N2, N3, like this, okay? And then we can just print this as fs DR. directly, see how it prints out. So person did 0 percentage one, and this is going to be too late, not 12. So print this so you can see here, okay, this is an interdependence is a flawed 1.442, and this is a string, Tommy Lee Jones. So this is another way of actually formatting your strings. Okay, now, in the next section, we're actually going to look and do the input statement. 19. Section-2.15 Intput: So in this tutorial, we're going to talk about input statements. Okay? In the simplest of all the input statements is just input this, okay? And we print that particular string. Ok, so now we are going to use the terminal because we have to input the data, right? So we go to Tools, Okay, view pooled windows and terminal. Okay, and we go to section two and we say Python, ok. And what was that input, right? Statement. It's asking you for as string. So string and returning the string, we are printing that string as well. You can also performed it ok. You can just say prompt for a certain input. Input string, this, okay? And this time it's actually going to prompt me, okay? So I say this is samples string and it's automatically coming in. You can also do one thing you want to make it an int, let us say. So you want to convert it into an int. So you can put in here itself, directly here itself. Okay? And then you can print that. Let's see. I will print the type, okay? So if I execute this from here, okay, and I say 12, and it's of black paint. So I can directly convert it. Also, what you can do, you can take multiple inputs at the same time using coma separation. Okay? So what I can do int of x, I've already and then converted it into int. Okay? And let's put an equal to here. Ok, and for x, okay? In input and input. O finally, to put this in a string, right? Okay? By comas, okay? Separated by comma, and then I'd say split. Ok, and that has printed by comma. So let's remove this and put string. And let's see how this works out. And remove this type of a type of b. I can just print e comma B for want here, a comma b. Okay? And let's run this. So it's going to ask me for integers. So I specify two integers, one comma four. And it's returning me. Okay, Columbia's one comma four and time B is integer and of course the ideal. So what b and integer, okay? So this is one way of actually inputting the data that does input without any prompt, input with a prompt, and take multiple inputs at the same time and split attain to an integer and a single statement. Okay? There is another facility which Python provides. Let me show you that I am committing this. You can import the sys library. And let's print syst dot arg v. Okay? And what we can do is that's input here, it's 1234. So now you can see syst dot arg v, which the library contains your Python filename and your parameters as well as a list. So what you can do is you can remove this Python. You want to add these two numbers, let us say, so you can say a alex, Okay? First is syst dot arg v. Okay? And we're going to use our slicing, right? One colon. That is, we don't want this input dot p y. We only want 1234, okay? And then we print, you have to convert this arcs 0 into an int. Okay? So two, add them together. And again, we'll convert the ABS one also into an integer and print it out. So now if we execute the same code, 1234, it is giving me four to six. It is so simple. So what we have done, we have taken syst dot arg, v. We have done cases used slicing and so that we don't take this input dot p y, and we just took 1230 for the two arguments, and we costed those to converted in fact those two arguments into integer and then being added them. So you could use it for float or you could use it for any purpose. As a matter of fact. Now, this is one way. Now let me show you. There is one more way which by components, which is E, which is most advisable and brain useful. That is, we import our parse OK library. And then what we do is we create a boss that object. Okay? So this is all object-oriented. So we will understand all this as we go. But as we keep coding, you'll understand ok. So we are using this art parser to create a parser object by calling the method. I'll go and buzzer and parsing description to it. Okay? Description. Let us say this is, this is a program to add two integers. Okay? And then what you can do. So now that you got the parser object, you can parser dot add argument, okay? And you can give the argument name. You can give the argument type. Type is nothing but Int, right? Your integer type and the help string, okay? What do you call this? Ok, a tendency. And we take this and we go to B, create another variable of b, okay? And then we get the arcs, okay? Alex is equal to dot fas arcs. Ok, so this way we are getting the arguments and then we print, OK. I'll start a plus B, no need for any conversion. So what we're doing here, so we're saying, okay, this, giving a description to this as well, see what is the advantage of programming like this? So if I want to understand this particular program, what it takes, I can just say hyphen, hyphen help. Okay, it's going to give me a beautiful helps syntax. So it's going to tell me what does the usage, OK, you say just I provide a and B. Okay. And what is the description of the program? What are the positional arguments? What is a you can specify in the help here. And what is b, okay? And you can specify all that here itself. So if I just simply remove this and give 12 plus 56, it's going to give me 68 directly. So this is the recommended way of actually taking inputs from the program, okay? Taken inputs into the probe them. Okay? Now, so that's all for inputs and outputs. So now let's go into the control flows in the next lecture. Thank you. So we're done. 20. Section-2.16 Conditional and Loops - Part A: Hi. Till now we have talked about sequential executions. Executions wherein we take some input and we calculate something or modify the input and we output that particular information, a particular information. So those are all sequential executions. So you have limited capabilities. Programs which have only sequential executions could do one or more tasks, not more than that, right? So, but you would want to do more complicated tasks. So in this lecture and in the subsequent lectures, we are going to talk about conditional and loop statements, wherein you could execute statements when a specific conditions are met. Or you can look through a specific set of statements repeatedly. Or you can break the execution loops. You can continue a specific set of statements, okay, without going further down in the loops. You can pass without doing anything. Or you can assert particular condition, or you can return from a statement. So all these kinds of complex executions, helpers and building more complex programs with more complex requirements. Okay, so first, let us understand the if statement. So in the if statement, we have, let's say a is equal to ten, b equal to 20, okay? If a is less than ten or let say 20, and we print a condition, ok? So that if we say that condition is satisfied, this satisfied, okay? So now let's execute this. So we execute this particular Python code. So you can see that condition is satisfied as got executed. Now, how does this understand that this particular statement is belonging to this if statement? Did you wonder? So? It is only because of the indentation that does the space. So I have maintained the space of four. You could also maintain a space of two. That's the default. But you could just put in to stay at least one space is required, okay? So that is one thing that you have to remember. Now, if I write another statement here, so this statement would not belong to this particular loop, but in fact, it will get executed right after the if test, okay, after the if, if test is completed, I mean if test and if the execution blocks of executed, then after that it is going to get executed, right? So indentation is very important. So please take care of annotation. And it is very much important in Python language. Ok? And as we keep writing, we will understand. Okay, so now the if statement is clear. Now let's try the if else statement. Okay, in the if else statement, What do you do? So you just can actually copy this same thing. And we can say, if a is less than 20 air conditioners satisfied, else, ok. So l v outside, okay, and you execute the else block, OK. So making sure our indentations are properly matching. Okay, Else block executed. Okay, now I'll say a is less than ten legacy so that this particular execution does not happen. Ok? Now if I execute this, so you can see the else block, block got executed. Why the else block got executed? Because this condition failed Haze not less than then in fact is equal to ten. So it has executed the else block. It is that simple actually. Now let's go to the next one. So in this, you can have if, else, if, and else. Okay. So how do you write this particular code? Piece of court? So if a is less than ten, okay? So let's take this stick and let's put in another value. If a is less than ten, we're just not the case. So condition one is satisfied, let's call it condition one is satisfied. Ok? Then lf, okay? You can say when do use lf, When you have another condition that you want to test for. Okay? So that is b is less than 20. Ok? So then you can say condition two is satisfied, okay? And I can say, and if c is equal to 2pi, So how would you check equal to, equal to, equal to o, right? And then, let's say condition three is satisfied. So here it will be l, f, and f, Okay? And then if none of these are satisfied, then else condition, the final else condition will get executed. Okay? This is else satisfied. Okay? So if I execute this, let us see what is going to happen. So we have conditioned three, got satisfied because is not less than ten, it is equal to b is not less than 20. D b is equal to 20, and c is equal to, equal to 30. Remember, you should not put it as equal to 30. It should be equal to, equal to 30. It will be a syntax that are otherwise. Okay. So that is, that is your if else, if, else if statement you can have a number of lift blocks. And within this lf blocks you can have multiple statements that can be executed. Say for example, I say this and ok, and a equal to, equal to 20. So what will happen now? So both conditions are not satisfied, right? C is of course 30, but a is not equal to 20. So what is going to get executed now? So else block has got executed. So all these conditions failed and the else block got executed. If any of these conditions pass, then it will just execute that and come out of this complete block. Okay? You need to remember that. Ok, because it is else, if OK, if this elsif notice, and if below this, there is a condition that is satisfied. But if this condition got satisfied first, then it will just execute this. And it will not execute any further. It will not execute any of these else-if statements, okay? Now, and one important thing, we don't have any switch statements like N, C, C plus, plus java. We don't have switch statements in Python. Okay? That's one thing that I would like to tell you. And while loop. Now let's look at the y loop. Hope this is clear. If else-if it's very simple. And, and while loop or duty, what do you say is equal to ten? Let us say while a is greater than 20, or let us say is less than ten, less than 20 will keep it as 20. Then print a, okay? A plus equals one. Ok? I keep incrementing a and it till it becomes 20. So what happens here? So initially it will check the condition is less than 20, that is correct. It goes and it prints the value of a, which is ten. Okay? And it increments a, a and it keeps on checking like this. Okay, delete reaches 19, ok, so it is going to print from ten to 19. So let us just check this. Yes. So you can see it has started from ten and it went on till 19. And after the incremented went and checked the condition and twenties not less than 20 after 19. So it failed and it came out of the loop. Okay, this is your while loop. Now, again, one more thing. In Python, we don't have a do-while loop. Okay? So that's the distinct. And now the next one is the for loop. For loop as one mode, very common loop that you need to understand properly. Already we have gone through the for loop. So let us say you can, the best thing is you set a range object. So for i in range ten, print i. So what does it do? It will simply print the value of i. Ok, I will just put it in quotes. I is equal to. So just to keep it clear, ok. You need to put in STR here when you are actually combining one string and an integer, you need to convert that integer to a string, okay? Otherwise you'll get an error. So you remember that when you're programming, okay? So you see here, so 0 to ten I is equal to 0 to i is equal to ten. And what you can do, you can also do an increment of two, okay? You're starting with and okay. So what can do? You can start at ten, okay? Your stop is at 20. And increment this too. You can do something like this. So how does it print here now? So you can see it has started at 1012141618 and it has excluded the 2020 will not be included, but ten will be included. Remember that the start will be included, the end will not be included. It would be less than the end. Whatever is the number that is less than the end. Okay, that is using the range statement. Ok, now another thing is your lists and arrays and all types of yoga sequence objects. Say for example, STR du is equal to hello, python, okay? Then for C, C and STRs, I can print C. Okay? So just put in some stars here. So just to make sure that we have proper separations or followed executions. So you can see here. So what has it done? Hello, space python. So it has I iterated through each of these characters and it has printed out the for loops. So the same can be extended to your list as well. Your tuple, or to your byte, array or array, any audio or any of these, any of those. Okay? So if I say 12345, then what I can do for i in l, ok, print and l, Okay? And again, I copy this one. Paste this here. So you can see it has printed out 12345. Okay, all these individual elements. So this is your for loop. Now in the next lecture, we are going to see the else with wildland for and all the other simple statements like bleak, continual bass or certain Druid. And see you in the next lecture. Thank you. 21. Section-2.17 Conditional and Loops - Part B: Okay, so we have completed the for loop and the next loop that we have as the next statement is else with the wildland or for which this particular statement is not existing in other languages. So this is interesting to see for people who have knowledge about other languages as well. So I'll just show you how it works. And let us say you have a while loop, okay? And I say this is 30, okay? So what would happen now? Your condition of a less than 20 will not happen, right? In this case, you can actually execute the else block, okay? And we can say, okay, while not executed. Ok. So let us see what will happen here. So while has not got executed. So this is one more very interesting fact about Python. It really tries to make the life of a program are very simple and very easy. Ok? And similarly, you have, you can apply it for your for loop as well. Say for example, you have a condition where you have no elements at all in your list. Okay? And you were trying to iterate. And if it does not iterate at all, then what happens? Then it goes here. And you can see for not executed, for not executed. So let us print this as valency. Yes, for not executed. So you can, you can easily execute a bunch of statements here when there is nothing that got executed in your for loop, it's that simple actually. Ok, now the next statement is a break statement. Okay? A break statement can be used when a specific condition is reached and you want to break out of a particular for loop or a while loop. And so what you can do say, for example, I will say for i in range ten, okay? And if i equals, equals six, okay? I can see brick, okay? That is, if i is equal to six, whatever it is, the immediate loop that is there will get broken. Okay? Now you see the indentation here. You will understand one more very interesting factor. So i is equal to, sorry, is equal to plus STR. I'm concatenating. Okay. And you put in as I, ok, now you see you how it works, the for loop. What are the statements within the for loop? All these statements, right? And what does this, where does this break statement belong to? This break statement explicitly belongs to this particular if statement, right? If you had actually put it over here, then of course, you'll get a syntax error because this if loop does not have any, any particular Anything to execute it. All right, so now let's print this out and see I is equal to one of the things that we are going to get. So five, c, 1-2-3-4-5, although the ranges till nine, the momentum reached six, it broke out of the loop. So that is your, so basically where do use this. So basically you want to say while True, you have an infinite loop, okay? And you want to break out of this loop, okay? I specify as i is equal to 0, okay? And if i equals, equals six, okay, then break. So this is fair. You would really use it I plus equal to one. So basically what you're doing here, why is this not working? If i is equal to, equal to six, then here it is. Okay, what does wrong here? So if this o, this dataset indentation issue here, right? So this has to be properly in ended, okay? Otherwise your indentation will go wrong and it will fail. Ok, i is equal to i plus one. And what do you do? You can print your eye here and you can see, so it is going to break out. Okay, so I just comment out this one and let's see how it works out. Yes, you'll see. So while loop has we have come out of the while loop. C, We've got their name, zip code of one. Why did we get an exit code of one plus STR i. I is equal to six. So print STRs objectives not callable. Okay? Yes. Tr is not an object. An object that is not callable? Yes. That come over here. So brent, i so okay. Let's forget about it. Let's not waste our time debugging this one. Put this here and we execute a density. Yes. So what happened? 0, 1-2-3-4-5. And it came out of the loop directly because at six it has broken. It has gone through the break statement. Okay, so what is wrong with this? We have to probably put it in, put it in double quotes as well. So we could have something wrong with the statement probably, or this seems fine. So if I execute this, it's returning an exit code of one. Yes. So basically that is happening because we have a variable that we have declared as SDR. So that's why it is not letting us execute this particular statement. So what we have to do here, we can just put it as STR of phi. Or what we can do. We can say i is equal to percentage i, OK, and percentage as well. So this is also going to work out for us. Okay? So this is what we have learnt in our print statements, right? So we'll comment this out and we'll execute this NC. Yes, I is equal to one to five. We could basically use the same thing here itself, here as well. Okay, so I think you understood, because we have already declared a variable whose name is SDR. So the SDL function is not callable after this. So that is why it has happened like that. Okay, so now we understood the break statement as well. Now, what does the next one? The next one is continuous statement. Okay? The continue statement is somewhat similar to the break statement. It's just that it's not going to break out of the loop. It is going to let you continue. Ok? So let us see. So for i is equal to I in range ten, ok. And if I percentage to that is if it's an even number equals equals 0, then continue. Okay? Otherwise you print, print i. Ok. So in fact, we're going to copy this and paste it here. And if you see what's going to happen, it should only print your odd numbers if i is equal to two. It is just going to continue back into the loop. It's not going to execute the next set of statements within the for loop. Okay, so let's execute this and see. So you can see here 3579, okay? And so I can actually print a statement here to make it more clear for you. Okay? I put in some stars here so that it becomes clear. So yes, say here 13579. So when i is equal to one, i percentage two is not equal to 0, right? So it's not going to continue back. It's going to go to the next statement when i is equal to two, becomes the condition is satisfied. It hits this continue statement. The continue statement will simply go back to the loop. It will not go to the next set of treatments. That is what is continue. Okay? So python is relatively very simple, okay? And assert statement. So the next one is a bar statement. So when do you use pass? So you don't want to do anything for a particular condition. Say for example, is 20, okay? If a is less than 20, ok? You just sit bars. That means you don't do anything. You tell the compiler not to do anything. Else perform some operation like print and then high or something like that. Okay? So if you execute this, what happens? It simply prints hi, okay? So pass statement is very much useful when you just put in pass here. And later on you might want to execute, you might want to implement something here, right? You just keep it boss over there. So if you remove this bars, it's going to be a syntax that are going to be a syntax error. So basically, let's say you want to write the implementation of I0 e less than 20 later on, then you can just put them parser, leave it here. You execute, you implement that electron. So that's like that also, the pass statement is very much useful, especially when you're writing classes functions at all. So you can start building up all your framework, open past statements everywhere, okay, and slowly fill up everything. And it will come out very well by them being very simple language, it makes your life very easily like that. Ok, now passes completed. Now the assert statement, assert statement is basically you are third for a certain condition, okay? Assert, OK, a, guess less than a. So let say equal to, equal to 20, okay? R equal to, equal to 30, then invalid input. So basically what you're doing here, you're just saying if a is not equal to 30, then you put it as invalid input. You throw an assertion error. Basically throw an error. So you see what happens here. So it has returned invalid input and assertion error stating that it is equal to 30. So this way you can actually put it in your statements, assertion errors. You can catch Erdos and you can show it to the executor or the execution environment desert. This particular condition has failed. So this is an invalid input for you or something like that. Or you can use it for your testing as well for your test cases. Okay? And then you have the final statement, that is a return statement. Returns statements. We will actually see more in case of functions, but I'll just give you a brief demo of water it end statement would look like. So when you are defining a function, you say def and you give the function name. And what you'd say is, and then you can put on a pass here c. And then I can call function one. Okay, FUN C1. And this is how I call it, okay? This is how I create functions. So I can just say print hello from, from one. Okay? So this is one way of doing it. Also, what I could do, I could put in a return statement and put this string here. Ok, so basically what is I'm removing the past now. Okay, it is returning a hello from function one to me. Okay? Let me comment this out. So I'm returning this and I can catch this into a, copy this into a particular variable, and print that X. So your function as basically evaluate something and returning low from function one. And you can put into a particular function one capstone that print that particular function, but you see it has printed out. So this is how you will return certain variables. You could also return nothing basically. So return, okay, and, or if there is a condition which is not properly satisfied while calling a function, you can just write this condition like if some condition okay, IS less than 20 or some condition like that, return. Okay. So that means you don't do anything after that, you don't perform any actions. So this kind of validation steps, all those things can be done using the return statement, okay, so we will see more details about this return statement when we are discussing about functions after a few lectures. Okay, so now we have completed all our conditional event loop statements. Congratulations, you have actually completed a major milestone in Python. You should be able to write QED statements and very easily understand how to write code based on your logic using Biden. Please don't forget to go through all the tutorials after each of the sections so that you really understand how to write the code and hosts symbol and how easy and enjoyable a distillate enlightened. Ok, now let us go into the next section of eddies in the next lecture. Thank you and see you soon. 22. Section-2.17 Milestone-1: We have completed datatypes, operators, output, input, and conditional and loop statements. And now we have hit the Milestone one. Okay, so in milestone one, we are going to use all these concepts and write a big example, okay, at significantly big program using all these concepts. So here we're going to look at book management example that is in section 2.17, Milestone one. I'm not going to explain you the complete program or do a hands-on. I want you to go through the complete program or the requirements and see how you would write it, and then come back and see how I have written this. Okay. You could be writing it a different approach, but you write it yourself, I would suggest, and then come back and see how I have written it. Okay, so now what is the requirement basically? So you have a library, okay? You have to basically create a program which works like a library, okay, which has a large number of books, okay? And all this data is maintained in a module called my underscore library. So I will show you that. So this is my underscore library, okay, where I have data.dat BY Python file. If I double-click on this, it's a huge file, okay? It's got large number of books that you can see. These are all arrays inside an array, ok? So basically you have each record in this array is nothing but a book ID, its title, and what is the author, okay, and all that stuff. There's lot of stuff that is written in here, OK. And similarly, you have all books, and similarly you have all members also. So basically you have two arrays of arrays, okay? One containing books, okay? That is each row representing a book and with each attribute in that row representing an attitude of a book, that is its title. Will the author was okay, what is its ISBN? 13, number one word, when was it published and all that stuff. Okay, similarly, you have about members. So if you look at members, the members would basically have the name, the age, and all that stuff. So if I go down yeah. So you can see these are basically the member's money. Okay. His gender, what has address was, what does age was and all that stuff. Now, your objective is that you should be able to login as using a member id and you should be able to search for books, okay, based on the book id, the title, the authors and publishers. So that is how I have written it. So till now you have not seen the concept of packages, but this is how you can actually create a package. So how you can create a package you can do, right click new. And I've created, I said new package, do Python package. And here you can specify the package name. And that is how this military package has been created. The movement the packages created there is an underscore, underscore IN IT. Underscore, underscore dot py file that's automatically created. Which means it has a package, ok, it is a blank file. You don't need to write anything in here. And whatever PDF files you right here, they can be imported without the dot py extension. So here you can see from my library, okay, I imported data. And now if you want to access the members or functions or whatever properties of this data, we have not come to functions, properties of this data. How do you do it? You say data dot and that particular variable, data dot all books or data.dat, all members, okay? Which is actually going to represent the members. Now what I've done here, let's run it so that you can actually understand I have executed. So first I'll give you the, give the member ID one. So it will give me welcome screen saying welcome to the Library Management System. B shake Abishek has a member id one, okay. And I can type help or hedge. If I type page, I can see all the searches that I can do. See select the option below to search for specific field and reserve a book, ok, the book reservation part is not yet implemented here, but no, sorry, anthologies and executing helped along by confine. We execute exercise one, okay? This is the correct one. Have existed, have executed the wrong one. Ok, so here, if I type H, I will be able to search files, search these books based on some texts in these books based on title, The Author, Publisher, ID, or I can actually quit. Okay, so if I say one for example, so it says search for a title. Now let us say if I say I search for a title which contains man string, ok? So it is going to give me all the books that are containing man in it's this thing. See here, Mandela, okay? And Mandela. Ok. So similarly you should be able to see all the books would have that man, particular madman string. And you can search for also authors. Say the author is Jane, let us say. So if I want to search for Jane, I say Jane. Okay, I would get all those books. Whose author's name has Jane. Ok. So all those, all those books basically. So that is how I have written all this. Okay. Now, how did I write it? So I basically imported the data, okay, and have converted, created two maps, okay, basically takes 2D objects and you see how I have populated that extremely objects based on the book id, okay? And then you can actually see through how, what have done. I have asked for the input for the member id, and I've checked if that particular member ID exists, okay, in this particular data members. So let us do a debug and see it will be even more clear for you. So if I put in a break point here, you've not seen the debug. I'll show you how to do the debug as well in this particular lecture. So I could click on this one. Okay, debug exercise one. Make sure you're debugging the right one. And you need to put a break point. So how do you put a breakpoint? You basically click here, click next to the line number, and it gives you a red dot. Okay? Now I can click on debug. So what this is going to do is it is going to, the execution would stop at this particular point wherever you have put this break point. So this is called as a break point. So now we're stopped at this break point, okay? Now, how do you move forward? I can simply say Step Over, okay? I can also do step into, if I'm calling a function, I could step into that function. But we are not making any function calls. We have not reached the functions yet, right? So if we go to functions, you can use this. Otherwise, let's say we step forward, okay. Now, let us see you have imported this data, right? Data is basically coming from my library. So if you want to see what is this basically, you see, if you want to see this data.table books, you can select that and you can click on this calculator kind of expression evaluator. So that would come here and all you have to do is press enter and it will show you what the data actually has. You can see it is basically a list which contains a list by itself. Okay? So, but what I want to do is I want to, what I did this, I converted this whole listed the map, okay, based on some key value pairs. Now let us see how that has been done. Let me close this. Let me put a breakpoint here. Okay, now, I don't want to go through all these loops by saying Step Over, right? So that way I have to loop through thousands of books. So what I can do is I can click Resume program. So if I hit this, it will come over here. Okay, now you can see this, all books. So if you see all books, click on the calculator and I hit enter. So now you can see, okay, it does a dictionary object. So basically it is a list of dictionary object, okay? Which is containing a key that is nothing but your book ID and your attributes in list. Okay? So that means a list containing attributes and a key for this. Okay? So if I can basically say, if I want to access, if I want to evaluate a key is 18952. So if I say 18952, hit enter. So you can see for that key, I have a list which contains 12 attributes. And all these 12 attributes are maintained over here. Okay? Like this, you can actually debug through all these things. So similarly members also, each member ID, I have actually given a assigned it to a member. Okay, if I put my breakpoint here, and again I click on this cell resume program. Ok, so now it has two. Let me see. It has to come over or it is. So let's do this one and say resume program. It has come out here. Right. Now you can see all your data members also. That is all members. If you see the all members, again, click on Calculator. You should be able to see, ok. So the all members 0 is basically 1466, okay? And it has a id, name and gender and all that stuff. So that is how you can actually see. So if you want to just see all members, all members as this c, it has got basically it is a dictionary with key and the value being a list of properties. Okay, so that's how we have evaluated. Next, we have got the member id, then we have written the welcome screen. So I would request you to go through all this, okay? And try to understand how I have written the input in an infinite loop, okay? So basically it goes continuously goes unless we press Q, Okay? We give a cue as an option. If you give us an option, five, then it was going to quit. Otherwise it's going to run in an infinite loop. That's why I've put in us while true. And within this loop, what are the inputs that it is taking and what does it printing out? So I would request you to go through each of these. And if in doubt, do a debug tried to understand if you're still confused about anything regarding the library or anything. You can immediately post it in the, in that particular lecture. Ok, post your message in that particular lecture, I will immediately give you a solution and give you a clearer explanation. 23. Section-2.18 Arrays: Hi, in this section we're going to talk about arrays. Unlike other programming languages where arrays are fixed and they cannot be, that dimensionality cannot be changed. At runtime. Python arrays are not fixed. And the only commonality between the arrays in Python and other programming languages is the array store similar type of datatypes, okay? That is, they can either store integers, they can enter float, store float, etc. Okay, similar type, not like lists, where you can store any kind of data. That is, you can have integer elements, float elements, string elements, it's not like that. So why did we, why do we need arrays? Okay, when we already have lists, you might want to understand that first because see the main differences days toward similar types of data. So they are much more efficient when compared to less, okay? It's faster and less memory consuming in terms of lists. In terms of lists. And similar to this, they don't have a fixed size. Their size varies and they can grow in their dimensionality dynamically, okay? And arrays are useful to handle collection of elements. Ok? And let us see now how do we actually create an array. Ok? So to create an array, first, what we have to do is we have to import headway as let's say a. Or. You can also import like array as start, okay? Import array as star from Eddie, import star from Eddie, import start. So basically what it would do, it would basically import the complete array, okay, and how do you define an array? You can just say array. First. You define the datatype, Okay? So let's say it is an integer data type, okay? And then we give it as a list similar to enlist in square braces, okay, on 46 to five. Okay? And if you just print the type of this type of array, let's see how does it look for us? So, okay, so we need to, again, my bad, we need to execute this again and select arrays. So you can see it is of type array. Okay? So this is how we create an array. And you can notice that you have only specific datatype and you have already defined the datatype, you're OK. And now Biden understands what kind of data is there. It can easily iterate through at a much faster pace when compared to lists, okay, listed has to go through each element, understand the type, and then go to the next one like that. Okay? So that's why these are all much more efficient. It is. Now how do you, I read through it is, it is just the same for AI in a print. So it's that simple. Okay? So the same i traders and all that stuff actually works here as well. So there's no there's no problem but with that, okay. And so you have different types of data, okay? So you can have a sign that a signed integer, you can have an unsigned integer. You can have signed floating points. Ok? You can have double-precision floating points. You can have a UNICODE, you can have different types of arrays that you can define. And you can also do indexing and slicing of these arrays. Ok? You know, the same slicing operations can be actually achieved using at 0s, okay, in, at fs. Well, so if I say print, now let's see there we have Dig than this, okay? We take this one and the same operations can be achieved. Lets say one colon. So it should, or sorry, a, a of one colon, right? So otherwise it will not understand at all. So it's just going to take only 46 to five, okay? And you can also do what? Minus four colon, OK. Print off. Minus one is five minus two, minus three, minus 40 a of minus four colon. So water, it would return data c. So it is going to return 4621, right? It is basically printing out minus one, minus two, minus three, minus four. If I make this minus three, okay, it's going to return six to five, okay? 62 phi. So you can do all kinds of slicing and dicing of this. You can call any element, ok, you can change any element on that stuff can be done on this. And there are a huge number of operations that can be performed on this, similar to append, okay? You can have bend an array. You can append, you can insert. You can insert into a specific location. Ok, you can extend also. So extended is nothing but you can add one more to add into this. Say for example, b. B is equal to Eddie, okay? Which is also of type integer. And then we have then 11131415, something like that. Okay? A is equal to a dot extend, OK. And b. So what would happen if I print a now? Print a. So let us see. So print a, Aidan, extend, extend. So they does not need to be, it does not return anything actually. So we just need to say a dot extent. And you can see, so it has extended, it has added all these into this, into the at a. Okay, it's that simple actually, there are a lot of such functions where you can. So if you want to do some kind of operations on similar type of data, it is better to use arrays instead of using. So what do you say like, instead of using lists, lists would be much slower than that operations. So when you're working with millions of data points or huge data or big data, you would need something like an array or something much more like NumPy. Okay, so when you're actually working on multidimensional arrays like mattresses and higher dimensions of mattresses, then it is better to use a library called numpy. Okay? We will understand this in a lot of advanced lectures where we are actually going to work on data manipulation. Okay? 24. Section-2.19 String Manipulations: Hi, in this lecture, we're going to talk about strings in DD. Okay? So in one of the sections we on datatypes, we actually talked about strings. But then this section, we're going to talk about strings in detail because things are very critical aspects of any programming language. It stores a lot of, can store a lot of important information. So let's look at strings again. So we know how to initialize a string we had understood before us. So, so you could have a single lane string using a single quotes or double quotes. Okay? And you could have SDR one and disc would be in double quotes. And you can have multi-line strings. Ok? So either using a single line or double line courts, ok, you can have different strings here. So this is one way of initializing your strings. Okay? And then how do you escape your strings? We talked about string escaping also. So STRs, STL for, Okay, we'll make this as SDL 0. So just, okay, so STL folders slash r slash t. So it's going to basically put in a dab between hello and world. Okay, if I print it. So I need to run it from here again. Strings. So R1 and strengths that we can see that it's a dab that got created here. If you want, you can have a new line, nasa. You land would be slashing. So you can refer to the Biden help and see what are their skip character so that availability slash and has actually created a new line. Okay, this is how we escaped the characters. But you don't want to escape the character than what you can do. Stl five, again, create a raw form, okay, by starting the string with R. And let's put this same string and see how it behaves. For the STL five. I copy it here. And SDR F5. So you can see that slash and is not escaped because you have initialized a string using row. Ok? So that is one more very interesting aspect about strings and you also, and what is the next thing that we need to look at indexing of strings. This is also pretty straightforward. How do you index your strings? So SDR six is equal to, okay? This is a string variable. Let us say. Then how do you go to the 0th element? So that would actually give you d, right? So if you execute this, it's going to give you a t. So basically you're indexing starts from 0, okay? And it goes stun STR, length of STR minus one. So you can say len off STR six, okay, minus one. So what it would do, it would print the last character and Titus e, okay? So that is how you can actually index your strings as well. So indexing Also we have understood, and the most important and most well-known one is actually slicing. So you can actually do slicing also. So SDRs, okay? Let's initialize another string. This is the string variable, okay? And then you can print, print STR seven. And let's say you want to start from one, okay? You want to end at eight, and you want to take a step of two. Ok? So let us see how it behaves. So hitch SI, so what happened? It has taken hedge and it has left one went to the next step, S, left one went to the next step I. So you can give the start index and end index that is excluding this eight and the step. Okay? So this is how you can actually provide you are distinct. And also what you can do. You can have SDR's seven minus seven colon. Okay? So what does it give? So all the previous seven characters starting from the end. Ok, so, so this is the 1c here. How many does given 1234567. So minus seven onwards or the characters you have got over here. So this is how you can actually find out and minus seven colon, minus one. If you do that, what is it going to return to you? So it is going to return only delta here. Okay? So a minus, minus 72, that is starting from a, it has gone to minus seven, minus six, minus five, minus four, minus three, minus two, minus one is excluded, right? So it has only given to l. So that is how you can actually do yours. What do you say? Slicing, slicing also, I hope it's very clear. It's very clear and straightforward. So it's very simple to actually get what you want from these strings. And then the next one is a repeating strings. Ok? So I find, say, let say SDR nine is equal to hello. Okay? I give a space, okay? Sdr nine into three. Ok? So it is actually going to repeat Hello, Treitz, see hello, hello, hello. So it is so simple. So you can just, you could have simply said SDR ten n is equal to o. Sdr nine into three, That's it. And print STL. Then here, you would have got. So it's very simple. Don't repeat your strings as well. Okay? So repeating of strings is also done concatenating strings. So if you want to concatenate strings, so what you can do. So SDR Lemon is hello. And SDR 12, let's say is world. Okay? And if you print SDR 11 plus 12, you can see that it will print hello world. Okay, hello world. So as simple plus operator can be used for concatenating and the multiplication operator is used for repeating, okay? It's just that simple. And then you have an operator. So in operator is basically, so let us say if, okay. Just put into it. Okay. I said all in SDR London. Okay. So is there an STL 11? So it should print true? True. Okay, if I put in as E in SDL lemon, so it should print as false because a is not present in H-E-L-L-O, right? So this is a simple statement which is actually going to find out a few that particular operator is present or not. Okay? It's that simple. So it also is done not combating strings. So how do you combat strings? It's straightforward. So you can say if SGR 11 equal to STR 12th, OK, print equal, okay? They are equal. Else can put an else statement. They are not, okay or not. So if you check now, so they are not equal, okay? If I put this also as Hello. So, and if I execute, it will say, let us see that is a space here. So if I remove the space and execute the article, so it is going to show it as equal. Ok, now we have completed the comparison operators. So what is the next one? Next one is strip the spaces. Okay? So you have basically let us say you have a string, 13 is equal to, okay? This is a string, okay? So you have white spaces at the beginning and at the end. Okay? And now what I say is print string is equal to plus, okay? Sdr Thirteen dot n strip, ok. Left strip. So water is going to do on the left side it is going to remove the spaces. Okay? And I will put a full stop here. And just to make it easy to recognize. So you can see it has not removed this base here, but death remote this base here. Okay? And you can use our strip, that is strip on the right side offered. So there should be no space between full stop in this. But here you have the space, ok. And you can also use strip, which is going to strip board the left and right sides. So this is very handy method which is going to be very useful for our operation. So whether you are taking an input and you wanted to make sure that our known whitespaces, okay? So because the user might enter some white space and you want us to bond those whitespaces. So this is one very important method. So after that, you have substring. So how do we find the substring sub string? So we'll have to say, let us say you want to find 0s in a particular string, okay? So what do you do? Str 13, okay, don't find. Okay. And you give the substring sub string is 0s, starting at 0 and ending at sea, land enough. Land off STRs 13. So that is your position of substrings. So if I print this one, let us see what it returns. Basically, I suspect it should return us her position offer to substring. So three. Ok. So there is a way Is that why has it given us number three? We have started at 0 and we have went up to length of STR 13, okay? And we have found a position, position of iss 0, okay? 123. So in this also, you have a position of another substring, right? This way it just returning a value of three. So that's also clear now. So this is how you find the first occurrence of any of these strings, okay? And after that you can, if you want, you can actually finder subsequent occurrences as well. Several example, I take this one, okay? You just need to put in a for loop. But I'll show you in a very simple dumps. So we have a AND X, okay? So you got the index and then what do you do? You start from index one again, okay? And again, so you take this and you say I AND x plus one, okay? And this is i and dx1. And print index one. Print IN dx1, Okay? And you also print I mdx. So let us see what has happened now. So it has got at position. Ok. So I just put in a print statement. Okay. So to make it easier to understand which statements are printing what, okay, so it has got a third position and it is also got it sixth position, right? So if you actually see, so here, 0123456 position, okay, so third position and six position, you've got to is, so this is how you can actually find out the sub strings within a string, okay? And what does the next thing that we need to look at? So you've got the competition, you did the stripping, you found load substrings. You want to replace certain, certain sub-strings, okay? And you wanted to splitting and chain joining. So let us see how do you actually find the substrings. Count the number of substrings. So how do you find substrings that or, or you want to replace the strings, right? How do you replace strings? So you need to file called the muttered replace. Okay, so what I do here, I have, I'll dig this SDR 13 again. Okay. And I see STR Thirteen dot replace, okay, what does the old one is? And what does it damn, replacing it with? The new one is not. Okay. This is not okay. And what does the line count? So ln counters what? Lincoln does default, I'll say 0. Then all we will not put anything for the time being. Let us see what does it, what does it going to return? So this should return SDR 14 as equal to this, okay? And print STR 14. Str 14. Okay, let us see. So see this not is not. So E's got changed to Okay. This is this also as God is not. And this is also what changed to is not. So this is how it has actually been replaced your statistic, okay? Now, what is that other element that we were actually looking at? Cannot find it all here. Let us see and replace. And if I put it as count number of times, only once, let us say, we say your implicit only once. Yes. So this is not only 1 third as replaced, it has not replaced the other 0s. Okay? So you just saw user-friendly if you put it as two and then this is also will be the place to is not. Ok. Let us see. So this is also has got to bless to, it's not that simple and straightforward. Ok? So looking at the help also is very easy here, okay? And not changing the case. Ok. How do you change the case? So it's very simple. Print and I can say simple, that's it. So this is actually going to convert decenter and upper string, OK. And similarly, lower. Lower will have changed this to lowercase. Everything will be in the lowercase. Ok, so I'll put in low birth also completed. Now finally, you want to find the substrings within a string, okay? We have replaced the strings. You have ud v have not done splitting and joining. Okay? So this is one more thing that we need to understand. Say for example, you want to split this particular SDR 13. It's very simple. Sdr Thirteen dot split and split it based on space, okay, the default space itself. And it is going to return you a list, okay? List off all the strings. And strings where you have split it out, spread it out and you have got the distinct okay, and how do we join? Join us the other way around. Okay, let me take this whole list. Ok, m l is equal to this, okay? But I didn't. Okay, what do I say? L dot joined or what do we do? Cuomo, dot, joy, Okay, and this is how we do because it's a string operation and put in the list. So what does it return you? It written backs, it returns back the string for you. Okay? So you can actually join it with a comma, right? You can join it with the whitespace s, But if you join it with the whitespace, you get the string back. Okay? So it's that simple. So join us basically what is the separator that you want to put in? And then dot joined and list the list or tuple or whatever you want to give out here, the eddy. And it is automatically going to join everything and convert this particular list into string. Ok, so it is that simple. Okay, now in the next section we are going to talk about functions. Thank you. 25. Section-2.20 Functions Part A: Hi, in this section we are going to talk about functions. Functions are nothing but a set of statements which are, which is given and the OK. Now, the advantage of using functions is you don't need to keep on rewriting the set of statements wherever you need it, okay, you can just call that particular function. And the compiler will automatically execute the set of statements that are defined under the function, okay? This improves your readability, First of all, okay? And also modularity. That is all that functionality which belongs to a single-step order single feature could be actually put into a function, okay? This way you're modularity also will improve. Your readability also improves, and your maintenance of cold also improves using functions. Okay, now, let's define a function first. So how do you define def function? Name of the function and the flower bracket, open bracket, close, okay? And then your statements within that function, OK? So this is how you define a function. Now, if I execute, nothing is going to happen because we have just defined the function. We have not called this function to call this function, what do you do? You can just say a few NC, one, okay? So it's that simple. So now if I execute this, so you can see the execution here. Ok, now what is, so there is, what is a doc string? Okay, we have called the function node that is something called docstring. So what is docstring? And show you. So I'll say def, okay, with doc string, okay? And it is nothing but a multi-line comment where you define about you document what this function is all about and what it returns and all that stuff. Okay? So this, you can say this is a sample description. Okay? So you can give a description, you can give all the returns. What are the input statements, input variables, and all that stuff it in this doc string. And this doc string will be used by some of the tools of Python to generate HTML documentation as well. We're going to see that in the future. Okay? Now, this is what is docstring, okay? You need to remember here. I'll just print something here so that we have, okay, that's it. Ok, so this is how you define a function. So the recommendation is for every function definition, you have a document string and this particular docstring should actually define what parameters this function takes and what are the return types, what it actually does, all of it, you can define her. Now, return type. Now every function can return some data, okay? So let us say if you have some a comma b. And you can say return a plus b. Ok? This is how you return certain statements. And there is no mandate like in other programs like Java, that you return a specific type always, you could have different if else statements. And within that defect statements you could return different types of data altogether, there is no restriction for you in Python, okay? I'll show you that as well. So c is equal to ok, some of ten comma 20. So, and if I print C, so what will happen now? So when I called some 1020 had been passed and it was the return in the function returned a plus b, that is 30, and I'm printing out 30 here. So it has pretty good 30. So what I can do is I can have a different statements here, okay? If something, if a is greater than b, and I'm going to return this okay? Else, so, okay, you need to put a colon here and we need to follow the indentation, right? Otherwise it will be a compilation error. And else, say, return none. I can actually return none as well. Okay? So if a is greater than b, so what is it going to return now? So if you see it's going to return null, okay? And if I change this to, let us say 30, now a is greater than p, So I'll get 50. Okay? So that means a is greater than b has become true. And it said return a plus b, otherwise it has returned none. So there is no restriction as to what you have to return. You can return different datatypes, okay, based on your conditions or your functionality, you are completely free on that. Whereas in other programming languages like Java, C, and other languages, you have to define what is your return statement explicitly, what is going to be your return type, okay? So that's one thing that you have to remember. Now that you have understood the basic concept of function, let us write some examples. Ok. In the first example, let's write a factorial. Ok, so this is one example that we are going to follow, right? Okay? So deaf factorial, okay? And I give a number, say x, okay? Now how does the factorial work? It is nothing but for odd is equal to x into x minus x1, into x minus two, and so on up to one. Okay? And you return that particular rod. That's it. Okay? It's that simple. So let us do this one. Let us define product as one. Ok? And we say while x is less than or x is greater than or equal to one. Okay? You have to continue this loop till it becomes greater than or equal to one, right? And we say. Product into is equal to x, OK? And x is equal to x minus one. Okay? And at the point that you need to understand this, you don't have statements or operators like plus plus x, sorry, plus plus x or minus minus X. And Python, okay? These kinds of unitary operators are not present in Python. You have to remember that. So these are presented other programming languages like Java and C, and C, etcetera. Ok? So x is equal to x minus one. So you keep on reducing the value of x and evaluate the product, and then you return the product, That's it. So this is your factorial. So this is going to be like x into x minus one into x minus x2, because the Earth continuously reducing this. Okay? So let's just see p is equal to factorial of, let's say five, okay? And print p. What does it return to us? 1-20. So what is this? Let's put it here. Five into four, into three, into two, into one, right? So this is six, okay. 2424 and to 51 to five. So we got the correct, correct value, 1-20. Okay, now let's write another example. Now. This example is going to be prime. Ok? How do you find out whether a number is prime or not? So deaf prime, and I define a number n, OK, pass the number n to it. And let's write some comments. Docstring, okay? So what does it return? It returns either true or false right? Through by false, whether it is a prime or not, it takes a parameter n. Ok? Now, what is it going to check? It should check n should not be divisible by by 22, N minus one, okay? Two to n minus one. Of course n will be divisible by itself, right? N minus one to two, you have to check, okay? And then you return whether it is true or false. Okay? Now what we do, we define is prime, okay? Is equal to true, okay? And let's return is try and in-between. We write a for loop for i in range, okay, starting from two, right? Two, n minus one. So you have to put any, if you remember, ranged from your previous classes. If you put n, It will go I iterate till n minus one, okay? And then what you do if whatever number you have given n percentage of I, ok, equals, equals 0. So if at any point between this two to n minus one, any number gets divisible, okay? That is, n becomes divisible by any of these numbers, then ys prime as equal to false. And I can break out because it is already false. Else, you just maintain iss prime is equal to true, right? You don't need to write this else statement like else. Okay? You can put that if you want, is prime as equal to true, okay? Even if this statement is not there, iss prime would always be true. But I'm just keeping it for clarity. Ok. So you understood I'm going to repeat again. It is going to check between two to n minus one, all the numbers. It is going to assign it to i. And it is going to check if n is divisible by I. And if it is divisible, then it, it is not a prime. It will break out of the loop. Otherwise it'll go on checking till it reaches the value of two, okay? Two to n minus one till it reaches the value of n minus one starts incrementing continuously. So let us check now. So print, okay, prime 1010 is a prime because it is divisible by two. Let us see if it gives us true, false. It, sorry, it gives us false. Yes, it returns false. However, if I okay, let me put it. 99 also is not a prime number. It returns false because it is divisible. And if I put 55 is a prime number because it's not divisible by 432, ok? So c, so it is true, this is a prime number, so it works fine. Now, what else do we have in this lecture? We have returning multiple values. Okay? So how do you return multiple values? So till now, we have been returning single parameters here, okay? Prime, okay, product, we are returning just one product, ok? We are returned whether it is a plus b or whether none, but you want to return multiple values, how do you return? So let us say, I will show you deaf. Ok, return underscore multi. Okay, I'm just going to write a function like this. And you can say return one, coma, two, that's it. So you can return multiple like this or you can also be done none if you want. You can refer to different types of data here, okay? Test. It is going to take all these things without any issue. Okay? So what do we do? How do we call it, and how do we take these values? We say a comma b is equal to o return multi, okay? And print a comma b. So let us see what it's going to print. It should print 12, right? It has printed 12. So this is how you basically return multi-valued. So where do you need multi-valued? Really very useful. Okay, so let me give you one example. So this is one of the examples that we're going to look at. The, right, the function which returns square root, double and square. Okay? So let's take this and say def. Ok. Return underscore, underscore dx1, okay? Take input a. And okay, before this what we do, I say import the math library, okay? Because we have the square root function there. Okay? So X is equal to math dot S Q square root, square root of a, and y is equal to math dot. Nope, we don't need to do anything for double, right? For double it will be two into a and Z is equal to squared, okay? Two star star, sorry, a star, star two. Okay? And how do you return it? Return x comma, y comma sit in the same order I am returning. So just, you just need to make it a point that you will return in the same order. So here what I can say a comma or you, ok, just to, I'll have different names here. U comma v comma w is equal to return. Okay? Multi example one. Alright, take, I give it as ten, let us say ok. Or I give it to us in line so that it has a square root. And I print OK, u comma v comma w. So it, it should return square root first, that is three and double would be 189 squared is 81, okay? 381. So yes, 3.01881. So it has returned property now. Okay, so this is how you return multi. In the next lecture, we are going to go further into functions and see more aspects. See you in the next lecture. 26. Section-2.21 Functions Part B: Hi, in this section, we're going to go forward with functions, other aspects of functions. So first aspect is passing functions as parameters. So functions are also like objects. Say for example, if I define a function, if you NC one, okay? And it returns something, so returns 20, let us say, OK. And if I print the ID of a few and C1, okay? So let's just see, you know, the id is nothing but the memory location as we have discussed in previous lectures. Ok, let us see what it prints out. So you can see it has printed out the memory location of this particular function. Note I have not given the places. I'm not calling the function, but I'm just looking at the memory location of this function. So that means like variables, even these functions have certain memory locations and they can be passed around. So I'll show you how they can be passed around. Okay? So let me define another function, okay? Def function two, which takes an arbitrary function, okay? And let us say it returns hello into whatever is returned by the function. Whatever is returned by the function call. This particular function. I'm just calling this particular function called fun. Ok? Now, what is fun? If fun is nothing but function one, then it would return 20 and it will be hello into 20. So hello called 20 times. So hello will get multiplied by 20 times every 20 hellos. Ok? So let us see if it works. If you NC2, okay, I pass if you NC one, I don't pass the call. I don't call it inside, but I just passed as function. Okay, so what happens? So you can see there are 20 times I got hollow statements. So that means the function, a function can be passed inside another function and it can be called, OK. That particular function can be called inside this function. Okay? This kind of functionality is also available and is quite famous. And JavaScript similar functionality. Now, you have understood passing functions as parameters. Okay, in the next lectures we'll look at lambda functions where you will see the real utility of passing these functions as parameters and how useful it is. Now, another very important concept is passed by value and pass by reference. Okay? So what happens is if you have any variables which are not mutable and immutable, then they will be passed as value, ok? If that mutable, then they are passed as reference. Ok, that is the main thing that you need to understand. Say for example. X is equal to ten, okay? Or let us say x is equal to 0. So this is a mutable and mutable variable, okay? So I will just say function three. Okay? What do we define it? Def function three. And I pass this x value. So I pass any variable, let us say into this, and then I will change the available of value of a is equal to 20. Okay? And I put in this value printers memory location, okay? Inside function. Inside function what it is plus STR of idea of the idea of a. And also inside the function. And also get the value of value also, right? Values equal to o is equal to two. Okay? Now the same thing I would like to print outside, outside this status, post calling this function c three. And I pass the value of x. Ok? So what is happening? Since it is unmute double, it will be passed by value. That means x will be copied into a and you will have a different memory location for a, and you'll have a different memory location for x. Ok, let us try this out. So what has happened? A is not defined, okay? Y is defined function because here we'll have to call it as x, right? So this particular, you have to call it as X here. A is a local variable to this function, okay? You'll understand this for the fall, these scopes as well. Okay, see your inside the function, the memory location. And sorry, this should be outside. Okay. Let us execute it for more clarity. So outside the function, the id value is different. So this ending with 912, this is adequate to 72, okay? And so, and also the value, okay? So just this. And also the value of the value inside the function is 20. The value outside the function is still 0. That means you have a different variable here, whereas you have a different available outside the function. That means x got copied to a value of x, or what you can say yes. And then this e value got changed. That means this memory location, this started pointing to a different memory location, which is having a value of 20. Ok? What we have discussed in our variables, okay? Initially e versus x was 0, okay? And when you pass x to a, x and a both were pointing to 0. Ok, however, when a was changed to 20, EI started pointing to a different memory location that is pointing to 20. So it has a different ID and this has a different time. So this is how it works for on mutable ones, say for mu doubles for example, that is which can be changed. I have 12395. Some, some list, ok. Now I create an other function, function for, and I pass a list to this, okay? And call it LST. Okay? I don't want to use any standard datatypes here and create confusion. And what I do is L st dot append, okay? And I append 990, okay, let us say, and I print inside the function I can take to take these two. I put here I d of S, t and value of NST, okay? And I also print this outside dysfunction. So I take this guy and printed outside dysfunction. Okay. Make sure you have proper indentation. Okay, this is l and this is L and there should be outside. Okay, so now what happened? Now let us just execute function for and I pass L. Okay? Now let's execute this. So here you can see inside the function, this is the memory location, even outside, this is the memory location. And inside we appended 99. And even outside it got appended to line 90. Why this has happened? Because it was passed by reference. That is the same list. Reference was passed on to the function four and it was appended to tie 90. So they were LST. These are all basically memory locations. So their memory locations are modified. So they're looking at the same list inside and outside. So ideally, you really don't need to have a return statement of LSD here, right? Because already it is passed by reference. You have all already have a reference to this, okay? Unless you create a new list and then you make some modifications to that list, then you would want to actually return that new list element. Otherwise you really don't need to return that element. Okay? So this is your pass by value and passed by reference. Now let us look at the very important thing that is arguments in the function. What are the variations in calling your arguments from within a function? Ok, so let us just create a function definition, pow, pow x. So this is a different, I don't want to use the math library name and I'm passing a comma b to it, okay? And I'm just returning a to the power of. Okay, so that's your listing. So how do I print it? Print, okay. Pow x ten comma two. Okay? So what does it do ten to the power of two, right? Now, this is positional that meets tennis copied to a, two is copied to B and there is a power that got evaluated and it got printed. Okay, so it has returned to be 100, right? But now if I change this by mistake, if I make this two, and if I make this ten. So you're going to get 1024 because you interchange it. You made a mistake, right? So how are you don't know the order sin, what do you do? Then? You can simply let me copy this to show you the difference. You can simply say b is equal to two and a is equal to ten. So what happens? A will be copied to here, B will be copied to this, okay, the first position will be covered because you're already explicitly specified the key word. So this is how you specify a keyword. Now let us execute it and see what happens. You get a 100, which is what we expected initially, right? So, so this is called keyword, okay? Now there is another thing called default. And you can actually specify the default value here itself, okay? In which case, I can just say print pow x ten. That's it. So it will automatically square this by two. So if you see it has given us a 100, which is same as your B is equal to two, because b is equal to two volts set to default. Okay? So what I can do, I can actually put in three here if I, if I want OK, so what will happen? So now it will take it as thousand, because now you have changed value. You have added explicitly provided a value of three, and it has taken that value of three, ok, that is default. Now, the next one is variable length. Okay? These are all very simple concepts. It's just that you need to know all these concepts, okay? Python is really very simple honestly. So let us see the variable length now. Okay? How do you specify the variable? Variable? And that is sometimes what you do is you want to pass a number of arbitrary number of variables, and you want a sum of all those arbitrary number of variables. How do you do that? You just say star arms, okay? And if you have any fixed length variables, you can specify here C, Okay? And the rest of them are all, so it will expect a, B, C to be specified, okay? And the rest of them are all belonging to start arms. Okay? So now when you specify like this, so let's do one thing. So sum Fx is equal to 0, okay? And we have four, okay? S in S, Okay? Thanks. Okay. Some plus is equal to S. Ok. And return. So now what happens? It, this arts is actually going to eat. You can specify multiple arguments and all those arguments will be added together and it will be shown, Okay, this answer is actually going to be a tuple just for information. Ok? Now let us see. Print sum n. I say ten comma 20, okay? What does it return to me? It returns 30 as expected, ten plus 20, okay? And if I want, I can and another set and at the 30, another number to it. So we expect 60 for this, expect 60 photos, right? You can have an arbitrary numbers being a tuple. You really don't need to have same datatypes as well. You can have different type of data, data types that are being passed to this variable length, okay? Variable length, argument, okay, now the next one is the keyword variable length. Okay? What does keyword variable length? Keyword variable length is nothing but a name-value pairs. Okay, so how do you define that? Say let us say def, display, okay? Dictionary, dict object. So you put, instead of single start, like you put here, you will put star, star, okay? And say Kw bumps. You can put any name. So I'm just putting in as kw args. Okay, so let's print this one. St R1 is equal to, I'm just saying key. Okay? And I'm just formatting the string 0 comma. I just put it like this value, okay? And one, and define the string. And then how do you traverse through dict? I have not shown you this one, x comma y, and we have seen lists, tuples all. But for mapping object, that is dictionary object. This is how you do it. And one spelling mistake here. I copy this Kw arts dot items. Ok. So this is also, this is a key, this is a value. Ok. Print STR one dot format x comma y. Simple. Ok. So it is going to say a key value is x and key is x and value is this much. Okay? And I'm just returning nothing. Okay? I'm just printing statements. So let us call this. So how do we call this? We call this as this. And we say a is equal to ten, okay? Comma B is equal to 20. Hamas C is equal to 30, okay? From R, D is equal to 40. So you can specify any number of arguments, key-value arguments here. So what is going to happen? Let us see here. So a is equal to ten, b equal to o. It has converted them into dictionary, and it has printed them out. So using key value, you can actually pass the key-value pairs as dictionary passed these variable name and variable values has a dictionary objects and you can use a dictionary inside your function to do whatever you want. So that is basically for your key value, key video, keyword variable length. Okay? Now in the next section, we're going to dig in a bit more further into functions and look at concepts like lambda, but interesting concepts and bidding and many other interesting concepts. Thank you. Sue. 27. Section-2.22 Functions Part C: Hi. So in this section will go still further into functions. So the first concept we are going to understand this, accessing global variables. This is a very important concept. Please pay close attention. I am defining a global variable is equal to one and followed by a function definition. Okay? And I'm going to specify as a is equal to ten here, okay? And print inside, inside function, okay? A as equal to STR of a. Ok? And I'm going to call this function. And, and I'm going to put into this value as well. And I call it outside. Okay? So now if I execute this, you can see inside the function, the value of this variable is ten, but outside the function it has one. Why? Because as soon as you've created a variable inside the function, it has created a new local variable, okay? The global variable is no longer being addressed inside this function. It has just a local variable. So that means you have two variables. One a global variable, which just outside the function scope, and a local variable we just inside the function scope. So this causes a lot of confusion because in other programming languages, it is not like that. It is different. But now you don't want this kind of a behavior. You want to access only the global variable even inside the function. So how do you do that? You do that by using the global keyword, okay, so before declaring or using this particular variable, you just say global a. That's it. Ok. And now you modify the value of a c. Let us see the behavior now. So you can see here inside the variable function, inside the function also the variable has value ten and outside also it got modified. So the moment you change the value, alternate so it got modified. So this is how you control your scope, okay? Whether, whether you want to access the global variables or local variable inside the function. Now, there could be an adder requirement, ok. Where you have one local variable that is defined as a, but you want to get the value of the global variable as well. Okay? So how do you do that? You can do that by saying AG Is equal to using globals, okay? Globals, which is going to return a dictionary object and you can give the variable name. So this is actually going to pick up your, the value of the global variable before this function got card, okay? And you can actually print this also n c. So let us print this. And we say this is AG, Okay? And this is AG, OK. So this should be equal to one, and it should also be the same as outside the variable, whatever it is printing. So let us check the behavior. Yeah, so see the global variable AG is equal to one, and this is also equal to one and is equal to one. So what is the summary of this global variables? If you create a new variable of the same name as a global variable within the function, a new variable gets created, okay, that will be of scope, of the scope within the function scope, visibility is within the function scope. So if you want to avoid that, you can use global a, okay? And if you want to explicitly access the value of a global variable, you can use globals function, okay? So that is what it is. Now, let us look at lambda hot anonymous functions. Okay, this is a very important subject and it actually makes your programming very simple, concise, very easy to understand, and efficient as well. Okay, so let us look at, look at this one. Now, if you want to get a square root, okay, let us say of a particular number, then you would actually have to import math, math library and then you return, okay, math.sqrt and b, right? So this is how you're going to get the square root of a function. So if I print this function, print this call SQRT 149, it is going to return you 3, right? It's written three points at all. We just collect. Now, if you want to define a lambda function, you know, so how would you define us and anonymous function? You use lambda keyword and the argument list. So I'm just making this SQRT as a lambda, okay? Argument list has only one. And what does it return? You don't have to put any return statement is just a colon and then math dot SQRT. And so it is going to return. Now, what is this f? This f is nothing but the anonymous function. Okay? This anonymous function. So you can call this anonymous function or passed into this anonymous function into standard libraries. Okay? So if you want to call this anonymous function with just say F9, so this is also going to return 3 for you. Okay? So this is what is lambda function. Now, let us see the utilities of these lambda function. So what is the first thing you want to call this using? You want to use this in a filter. Okay? So what does filter do? Let us look at the filter usage. So a filter takes a function basically, ok, and also it takes a list or an eye tradable, iterable. It could be a sequence object. Ok, so let us create a list first and it filters out certain members based on the function, okay? So whatever this function returns, whether it returns true or false with the filter, it will, based on that, it is going to actually filter certain values. Or let us say. Heat. Okay, I have a list like this. Now, I'll just show you, I'm just going to directly pass. And so the first is a function, ok? So I'm going to make a lambda here. Lambda function, okay? It's input will be individual element, okay? Colon. And then I put an air condition. I don't put in a condition, I just say x, ok? X percentage two equals, equals 0. That means if it has an even number, ok? So if it is an even number, this returns true, right? And comma L list element, okay? And I can put this to the list, cast it to a list that is convert this into a list. I traveled into enlist. That's it. Okay. Now if I print lst data, see what's going to happen. So it has given me 2468. That means it has only given me the even numbers, the filter. The lambda function that has been passed to this particular, this returns true only in case of even numbers, okay, from the list. And it returns false in case of odd numbers. So only the even numbers will be added to this new list. So that is how you can use a lambda function. You can see how simple it is for you to actually filter out certain set of certain elements. You don't have to write a for loop, you don't have to write anything, just a single one-liner. So that is the power of lambda functions. Ok, let us look at another example of using filter that isn't map, okay? So maps are similar to filters. It's just that you can modify the list in a map and the map function. So I call it map and lambda. Okay? It takes each value of a list, ok? And let's say it squares this value, okay? And then I pass in the lambda as well. It's that simple. And now I can convert this into unless, unless t one, okay, and just say list, list and print unless t one. That's it. So if I execute this, you'll see all the individual elements of L have been squared. So this is the advantage of using map, okay? So these lambda functions, anonymous functions are really powerful and you can write a lot of functionality in a single line. So that's the advantage of using lambda functions. Okay, now let's go into decorators. Decorators are also some things where something which is very important and very useful. So let me tell you how a decorator box, okay? If I declare a decorator, decorator basically takes in a function, okay? And then creates a new function, okay? And it uses that function, calls that function like fun. Okay? And modifies the value of that function. That is value, say I modified I double this value, okay? And it returns this inner function, okay? So that's how it is. So now if you want to call this function, how do you do it? So df, numb, let us say you have created function, okay, which you want to modify basically. So return ten, okay? Now I call this function decorator dc1. Okay? And I pass num function to it, okay? Which returns to me, okay? A function called fn. And I can call this function. Okay? If I call this function, let's see what happens. So I need to put in here open braces and closer, close braces, right? To define it as an integer. So C, it has, it was ten and the value got changed to 20. Okay? So what happened here? Be passed in num, okay? And the decorator created an inner function, okay, which calls this particular function, gets the value and doubles this value. Okay? And the decorator actually returns the function definition that is just the function itself, the inner function. It does not make a call. Later on you actually call this. So how do you use this decorator without all this? So what is the utility? Let us understand of this decorator. It is basically used to modify the behavior of functions that have already been defined, okay? You already created a function, but you want to modify the behavior of that function without actually modifying that function. That is where you need to use a decorator. Now, you don't want to do these two steps in the decorator. So how do you do that? How can you achieve that? By just putting in air and percent dc1? That's it. Now, if you remove this and call print num, so it is not going to return ten, but it is going to return 20. Why? Because you have said you apply this decorator on this function. Okay? Now, if you have another decorator, let us say, okay, and this other decorator multiplies it by four times, okay? That particular number. You can actually applied that also here, DC to. So I changed this to dc2. Ok. So now what happens 22 for 80 forced it is going to convert ten to 20 and then 20 to 40 to 80. Okay? You can see that here, scientists become 80. So you can understand how simple the life has become. You have created a function or you already have a function. You don't want to touch that function. So you just apply decorators to it, which modifies the behavior of that function. Function calls. Okay, that is the meaning of decorators. Now, the last topic is generators. Okay? So in generators, what do we do? We basically generate certain numbers. So see how by using the yield keyword. Ok, so let us see I call my evens, okay? Events and x comma y, the upper limit, the lower limit. I wanted to list down all the even numbers. So how do I do that? While x is less than or equal to y? Ok? I say if X percentage two equals, equals 0, okay? I will not return, but i will yield, okay? Yield x, OK. And I will just say x is equal to x plus one. Okay? And I don't do any return statements. Now, if I print this ears okay, list, okay, my evens, and I give from 0 to ten, and actually I converted it into list. Okay, that is, that is how you push this idea relatable object into a list. Okay? And if I execute this syntax error, so I have to put a colon here, okay? And if I execute this, so here's 0246810. So basically what it has done, it has yielded, that is, it has extracted internally all the values that need to be returned and return at the end of the function calls. Ok, so it is, you don't have to write l, create a list object, append all those elements into the list object, and return all that stuff is taken care by this particular eels statement. Okay, so that is the advantage of generators. So we have reached the function's End of the functions. Now, in the next lecture, we are going to look at lists and tuples. Thank you. See you in the next lecture. 28. Section-2.23 Lists and Tuples: Hi, in this section, we're going to talk about lists and tuples. Okay? So we have already discussed lists and tuples in datatypes, but I would like to reiterate once. So we are clear about it because they are very widely used and you should have a clear concept. So let's go through the definition of lists and tuples first. So how do you say define a list? So you can say and is equal to, okay? And within the square braces, you can specify dest, okay? And I can put in any kind of variables here, okay? So quick. And whatever I can have, etc. Okay, though, only thing different between lists and tuples is you will have a circular press OK, instead of the square braces. So that's the difference when you're actually working with tuples. Now, you want to create a list from a range object. So you can actually say, you can create it using range 0 to 100, let us say, and with a step of two. So what would you do? It would actually create a list, but a 0 to a 100 auditor even numbers. Ok, so I'll just execute this one and show you, sorry, less than two points I need to print, print and one executed. So you can see it has created la huge list, okay? And how do you append two lists? It's very simple. Okay? So if I have L here, and if I say L3 is equal to 9977, let's say OK. And if I say L3 is equal to, just say L1 plus two, that's it. And if I print L three, it does actually going to concatenate these two. So L1 plus L2, L3. And see, it does actually. So for clarity, does append this two L. Okay. So it's easier to see the result. Yes. So you can see ninety nine, eighty eight, seventy seven. So this is how you actually appended, okay? And second thing is very important thing that you need to understand this. Say if N2 or can be got L3. Now, if I say L4 does a goto L3, okay? So what it does, it basically creates a new variable, but bought L4 and L3 are actually pointing to a single memory location. Okay? Now, if I sure see L3 dot append, okay. Three dot append 66. Okay, I put it as number only 66. Now, if I print L3, which I'm already doing her, so what would happen? It is showing 66 here, and if I print L4 also, so for that is also going to have 66 Y because both L3 and L4 dot actually pointing to the same, same memory location. But you want to have, let us say you want to clone it, okay, then what do you do? L phi is equal to N3 or L for whichever one you take and put a colon. That's it. So what will happen now is L5 is going to be a clone of L3 and L4. Okay? Now if I say L5 dot append, and if I say 0100, ok. And if you see L3 and L4, it has not changed all that. Okay? If I print L five now, so it has got a 100 or here, okay? It's, it's a different one here. So that is one thing that you have to understand. Okay? So cloning, that is the difference between cloning and actually referencing each other's ok, that's the thing. Okay, you can also do sorting. Ok, sorting is also very simple. And if I say L phi dot sort, okay? And it's automatically going to sort my values here. So let me do it like this. And five is equal to 154890 or something like that. Okay? And if I print L five, okay. I don't print all this anymore. So let us see how does it sorted. So 013589, it has sorted in ascending order, okay? You can also put the reverse is equal to true if you want, reverse as equal to true. So what would happen in this case? It's going to sort it the other way around descending order. Okay? This is the easy way of sorting. And you want to count the occurrences. Say you have nine again, five again, 0 again, 0 again. Okay? I just copy this and say, OK. And if I want to count for the currents of any of these things, then I say L phi dot count, okay? And what to or say? I want to count the value of occurrences of 0 and L5. So it has given us three, so 123, so there are three occurrences of 0. And if you want to count the occurrences of five, you have two occurrences of Y to adventure so far, that's simple. Ok, now, you want to find common elements between two lists and tuples sorts. It could be a list or tuple. All these only modifications are not applicable. List of all the operations are equal and for both lists and tuples, okay, that you need to understand. So if I have two elements, okay, do lists L5 and L6. And I wanted to understand the, what do you say, like the common elements between these two. So how do you do that? I'll say else S, S five is equal to set of L5, first-day converted into set as six is equal to set of L six, okay? And then I print out, print S5 dot intersection, intersection of S six. So it is actually going to print the intersection between S5 and S6. So let us see it is 95. So what are the common elements between this and this? It doesn't 95, okay, so this is how you find the common elements. So these are the basic operations apart from the slicing operations that we have seen. How many number of times and many other lectures for all the sequences. So these are the things that you basically need to understand. Okay, now we have completed the basic Python, so we are good enough in a writing large number of lines. So please make sure that you go through each of the tutorials that are exercises that are mentioned between each of the sections so that you don't forget anything of these basics. And we can easily translate into the advanced concepts of Python, like classes, inheritance and oops, concepts and many more things. Okay, thank you and see you in the next section. Good. 29. Section-2.23 Milestone -- 2: Hi. So now we have hit Milestone two by completing arrays, string manipulations, functions, lists and tuples. So let's look at Milestone two, what we can achieve here. So basically we have written in a procedural manner just to using conditionals and loops statements in the previous milestone. Here what we are going to do is we're going to put all of them in two functions. Ok? So a function to actually load the books, okay, and at the helper function called by the Lord books to extract the book details. Ok? And then you also have a function to search for your books. And for the search we are using another library called fn match. We are not going to write the search functionality. We have just going to call the FN Match dot filter, okay? Which is only going to give them match results as a list. Ok? And then you can use that and you can find out what are the books based on the list. Okay? And now this particular search you can see takes kw args. So one of the argument is basically your attribute, okay? And its value, that is, you can set title Is equal to man or something like that. Now when you search for it, it is going to only search for that particular filter, okay? Whatever you have given in the title, it is going to search for that string and it is going to produce a, give it a decides. Okay, so basically you made it all modular. And another thing that you have done is I have done is I have basically created keys for all these fields because in the previous exercise we did not know Waters book ID, which field, which one is title, which one is author, right? It was very complicated if you actually open your data, Data Python file. So all you can see is it's got some values that said you don't know which one this is our IDB can understand, but which one is title. So all that I have put in correctly here, okay. So you have a book ID, you have a title, you have authors, and you have totally 11 fields. But we want to only these fields to be populated in internally in our data structures. That is in our all books. Okay, so that is what this load book is actually going to do. So what it's going to do, it is going to go through all those books that are mentioned in this data books, okay? And for each of that book, it is going to only extract those key values. That's it. Only extract the key values that are present here. That means it knows book ID would be 0. Ok, it's going to extract that and put it as a name value pair. So that's how it is going to do it even for your members. So let us just debug ones to just let me just show you that I put in a break point here, okay? And I'm going to right-click and say debug. Okay. So let's wait for the debugger has come here. So the moment you see that it is selected here and this screen has appeared, you have seen the debugger here. So if you see all books here, okay, here also you can actually see, you can see as previously, it has got an ID, okay? And previously this was a list, right? This itself has become a name value pair down. And only those names and values have been used, which are mentioned for this, which are mentioned in this key. Ok? If you want additional fields or you more than others though, say after phi you want sixth, seventh field also, you can put in all those things, okay? Those things also will be coming into here. So these are also name-value pairs. Previously this was a list, ok, and similarly for your members as well. And I have also written some additional functionality to actually do the reservation as well. So let me just run that and show you that new functionality. Instead of debugging. And what I do is I click on Execute. Okay, now I give the member ID. So it says, okay, welcome to the Library Management System, Abishek, okay, then I type H. It will give me all the options. Say if I use Title, okay? And if I say, man, so I'm giving in small, but still it is going to search for capital man, also, small man as a less capital band. Okay, I get all the search, you know, Now, let me remember this, okay, 4-5, 3.3.4. So now I want to reserve this book. So I say five, okay, five is for reserve, right? So I get the fifth option. And so what happened to the fifth option? What five? 3.3.4. Okay. No such book. Ok, let us give the fifth option again into got stuck for some reason. Okay. So enter the book id for 5.3.3 four. So it says reserved book for me. Okay. And now I, again, I can hit H and I can see if I wanted to see what are my books that I got us out. I can click on six. It's going to, I can just need to enter. That's it. And it's going to give me the book that got preserved under my name. Okay, so this is the new functionality. How did I, I also added the mess. So that is c. If I have reserve, that is five. In this loop. If I give the input as five, then it is going to go to the fifth option. And in the fifth option, what it is going to do, it is going to basically get the value that has been inputted. Ok. And if that inputted thing is there, the search queries already is there. That means if that key is existing, then it will go to the else. Otherwise they'll say no such book. Okay, and then it will deserve the book. So you need to look at how the reserve book has been implemented. So these are all basically, if you see it's all, it's all working revolving around lists. Maps, tuples are tuples. We're don't have lists and maps and all that stuff. How do you manipulate around it? How do you create those key value pairs? And all that stuff. Okay. So I would want you to go through each and every line. I would want you to. So basically take each option and put in a break point for each of these statements, elif statements and see how they, how it is working. Okay, so here you can actually go in. And what do you say? Like, you can step into each of these functions wherever you called search books. Okay, such books. So if you put in a statement here, so that is three. What does option three? Threes publisher. Ok. So what if I do a debug now? Okay, I will just show you. So this is going to give you a proper hands on. Okay? So you are actually working on a real cold basically click on Console, okay? And so what you do is continue asking you for member input. So I give it as one. It's come here. Now, I give it as three option because at three, I have actually put in the break-point right? At three. So if I say three here, enter the publisher. Ok, publisher, let's say I put it as EST, something. It's come here, OK. Now I can step inside. So instead of step over, I say step into. So what happened now? I got into search books. You want to see kw args snow. Select this. Click on your calculator. Hit enter so you can see what I have given. I have given the publisher and I've given star, ESD star. So it is going to search for study as T star. And after you can put, if you put here, and if I say continue. So I should be able to see the matching books, which has a publisher who's who has that ESD in it's this thing. Okay, so that's basically that's how you are going to look at it. Okay. So now if I look at this, okay. If I look at this, oh sorry. So I basically need to look at matching books. Matching books. So you can see the structure. If you see the publisher, the publisher would have EST and Etsy digest, ESD, ESD, that is how it is actually picking up. So I want you to go through each and every line for each and every functionality and try to understand how to write the code and write the code yourself and see then that way you will have a much clearer picture about how you have to write these big programs. So this is the best way to learn, okay? So we don't have to understand everything in Python, but the most important thing that we have to understand is to write programs, okay? Write programs freely and very fast, as I've explained you in the first introduction video, this is the best language for doing fast prototyping and to immediately see how the result appears and all that stuff, okay? And for wide variety of problems, starting from web development to database programming to visualization for everything. So that is why you should learn how to code. So that's why I want you to quote, If you have any problems, asked me post MI in the message. If you need a new video explaining in detail, do post that in the message, I will take care of it. Okay, thank you and see you in the next lecture. Bye. 30. Section 2 End: Hi, so far we have covered the basic concepts of Python, including datatypes, operators, input-output, conditional land loop statements, at is less and two books. We have also covered string manipulation functions. You of course exercises and assignments between each of these lectures. As part of advanced Biden, We will now cover classes and objects, object-oriented programming, abstract classes and interfaces, exception handling, working with files and vitamin threads, networking and sockets of database connectivity, and exercises and assignments. Thank you and see you in the next lecture. 31. Section-3.2 Classes Part A: Hi, in the previous section, we talked about the basic concepts of Python, starting with writing commands and writing small programs, and using different data types. Working with input and output, working with lists, tuples, strings, operators, and finally, writing functions, etcetera and a whole lot more. We have gone through a lot of tutorials, Humpty number of quizzes to understand how to write the basic Python code. In this section, we are going to jump into the exciting world of object-oriented programming. So what is object oriented programming? Or, oops, concepts which is being used in all programming languages like C, C plus plus Java, Python next, UTRA, Of course not C. So C plus plus Java, Python and other programming languages. So object oriented programming is basically a paradigm which consists of two concepts, two main concepts. One is a class and other is an object. So a class is nothing but a blueprint of an object. Okay? So it tries to mimic the real world object into the virtual world of software. That is the basic idea of a class. So a class is nothing but it contains variables and it contains certain methods. Variables are nothing but attributes of a class. For example, if you take a car, a curves attribute would be its model. It's make, its color, the price, and how many number of people can sit in their car, etc. And the methods are nothing but the operations that you can perform the car, like you can accelerate, you can decelerate, you can add fuel, okay? And lot of other actions that can be performed. So a class is a conglomeration of both attributes and actions or methods that can be performed on the real-world object. Ok, it is basically a blueprint. Now comes object. Object is nothing but an instance of this class. So basically you define a class and you instantiate this class. You could create a car with a model and a make of MA studies. Or you could make, instantiate a class with a model and the makeup of a Toyota Camry or any, any of those classes. So they are the concrete objects, real objects which actually follow the blueprint of a car class. So that is what is the definition of class. Now, let us see how do you define a class. You define a class by using the class keyword, okay, followed by the name of the class, okay? Mostly it is better to use a capital, capital in the beginning and what it extends, OK. You could, if it does not extend anything in default, by default, it is going to extend the object. Extension is nothing but we are going to talk about extinction. I'm just going to give you a brief idea. Extension is nothing but it is inheriting certain properties, okay? So that inheritance, so it has all the classes, would inherit and object, okay? So you could inherit from, explicitly, from your user defined classes, art classes which are available other than object. But if you don't specify, it is by default going to take object. So you can explicitly also specify that it is extending or inheriting from object. Okay? Now, how do you define the members of a class? The members of a class are basically defined in an initialization method which is called init, okay? And here you say self dot model is equal to see Toyota and self.age make as a CTO Camry. Okay? So this is how you define the variables, okay, are the attributes of a class that is, now we are going to discuss about self, but what selfies? Nothing but it is the instance of the class. The current instance of a class for itself is nothing like it. Nothing but this operator in your c plus, plus or in, in your Java, okay? So that is what is self? Self is nothing but it is the current instance which has actually, which has actually been instantiated, which is under question. Okay? So this is how you define your attributes and how you, how do you define a method? You'll say def and say, we will say print, Let us say car details, okay? Or we could insert, say, Info. This would mean better. See self has already come here. And what do you say? It would actually print the information. Okay. That is self.age model. Okay. So discard, let us write it in a format. Okay? This car is yes. Okay, mortal. And 0 comma me. One dot format, right? And then you put it in as self-taught model, coma, self dot make. That's it. Ok, So this is how you define your methods, okay? Now you have defined the class. So if you run this particular program, nothing is going to happen. You see does not go into print anything for you. Let us see that. So I'm going to call Classes one. And you see there's nothing that got printed because this is just a plain definition like you did in functions. Okay? Like you define functions. We have just defined a class. So now if you want to instantiate a class, what do you say c is equal to car, okay? And then what do you say? C dot print. That's it. It should be sorry. This way. C dot info, that's it. Okay, now you're not passing self-efficacy here. The self is something which is intrinsic to the class. Ok, this is a default parameter. This is the first parameter that you can that is passed automatically. Okay, so now if I execute this classes plus one, you can see this has printed out, this is a car, this goddess. Okay, there's a spelling mistake model and make. Okay, so this is how you define a class of collected it. This is how, this is how you define a class. Now, you can also remove this, okay, you don't need to define this. You don't need to specify that it is basically a class which extends object. It is default. By default it is going to inherit all the properties of an object. Like for example, an object would have an ID attribute, which we have seen for other variables, right? And the type attribute. So we have seen that type attribute when it come when we were defining the datatypes. So if I print the type, that type of c, c it is of type car, okay? So that it's fortuitous. So you can easily understand from the definition, right? So you can also check the ID attribute of a class. Okay? So the idea is basically going to give you the memory location. At which memory location was this particular this variable has been stored, ok, this system memory location. And so how does this work now? So we understood this now, we have understood variables. Variables are nothing but attributes or properties or whatever you can say the model make all that stuff okay? And methods are nothing but the actions that you can perform on this particular object. You can do an acceleration or deceleration, okay? You can maintain a current speed that if, if I say self-taught speed is equal to 0, ok, it is initialized to 0. Now I can write a method def, okay, accelerate and specified by the parameter called. So what it is going to do,, speed, okay, plus ten, okay, and I can see deaf decelerate. Ok, self by default is going to come. Sorry, here we will say speed plus is equal to S, okay? And we define S over here. So that is how you have to do it. Basal rate by a certain speed. So what do you say? Self-taught speed, okay, minus is equal to S. Ok? And you can also print the current speed, okay? Modeled make and speed. And I again put it as two. Okay? And I can actually make it this speed. It's that simple, okay? Now, if I print it now, current NFO, the speed is seed. All right? And if I say c dot, accelerate and I see a 100, then what would happen? The card would be executed running at a speed of 200. Ok. Now if I decelerate, it will run at 0, decelerated by a 100 children at 0, you can see the information. So you can have different attributes, you can have different methods. And in all these methods you can actually pass in certain variables. Ok, now, that is, that is what is your basic class definition. This is how it goes. Okay? Now, how does a class get instantiated, instantiation of a class? Now, if you see this one, okay? Instantiation home, does it get instantiated? First? First, what happens? It, okay, it allocates a memory for the class object, okay? It allocates, okay. Remember E for the class and how much memory delegates. It depends on your methods, but it's also going to occupy some memory. And also your data members are going to occupy some memory. Okay? And then the second thing, what it does, it calls this underscore, underscore INSEAD. Ok. So it calls the constructor, basically calls the constructor. Okay? And then finally what it does, it takes that memory and assigns it to the variable like C, Okay? Two variable, ok, so that is how it is. So basically distinct, that memory area is tagged to this particular location. So this is how is the memory allocated. Okay, so in the next section, we're going to talk about constructors. Note that we have understood the basic concept of a class. Let's go in and understand how we have to construct classes, okay? And, and how, what are the types of variables that we have? Okay, see you in the next lecture. Bye. Hi. 32. Section-3.3 Classes Part B: So in the previous lecture, we talked about the definition of a class. How do we define a class? How the memory is allocated to a particular class, okay, what is this underscore? Underscore IN AD and what are the methods? What are the attributes, all that stuff we have understood. Now in this class, in this lecture, we're actually going to understand about constructor and also about the self. So what is the constructor? A construct that is nothing but m method. It is like a method which the Python automatically calls during the initialization. Okay? So when you're seeing car, see car, okay, then this underscore, underscore INET got executed, which is why when you're actually printing this particular Info, you're getting the model as two eta, OK, and make us Camry. How did you get this? Because this is what is getting called internally. We didn't call it here, right? So this is what is the constructor. So basically a constructor gets executed by the biotin itself when you're instantiating class. Okay, now there are and it constructor would also have self as it's default first parameter, which of course is initialized by the bitumen itself. Okay, the pythons virtual execution environment itself is going to initialize this particular self. And what would be the value of the self? The value of the self as the sea itself, ok? Whatever it is, see that itself is Boston as a self by the virtual environment, virtual execution environment of biter. Okay, now, each of these default, Each of these constructors could have certain parameters like functions, ok? There are also like functions. It's just that you could have some parameters also that can be defined. Now in this scenario, if you see when you instantiate a class, it's always going to be of type kennedy. Okay, let me comment this out. Okay, also comment this out, and let's put this and C. So we have not passed any parameters and it is always going to be of model, Twitter and make us camera. Ok. So what we can do is we can define another constructor, a deaf underscore, underscore init, okay? Synth or self is automatically created. So, and then we see Model coma make. Okay? And then we instantiate here. Self dot model is equal to model, okay? And self dot make, physical make. Okay? And how do you instantiate? How do you set this? So let us comment this out. We don't want to put it as iodine cavity or here. Okay. So we call it here. Okay. We say okay, my TA and okay, let's see, lexus this time. Okay. Lexus. And now let's try to print this out. So what happened now? The underscore, underscore, the INA D is going to get these two parameters, Toyota and Lexus. Okay? And this is the constructor that is going to get caught. This constructor is not going to get called. So this is called as a default constructor, no argument constructor, that means you are not passing any arguments to this. Okay? Here we are passing two arguments, model and make. So that is what is getting constructed over here. Okay, now let's execute and see this one. So it takes one positional argument, but three were given. Ok. So let us look at this. Deaf underscore, underscore. Underscore, underscore. So this is how you have to specify your constructor. Now let's execute NC. Okay? Card has no attribute, speed, okay, so we'll have to maintain speed also self-taught, speed is equal to 0. Okay? So let's see why, why do you need to maintain this? Because it is getting it is calling this particular constructor. Okay? And after that, the invoice getting card. So when the info wars getting called, it, notice that it is printing out speed, but the speed was not defined. Okay? So here we have defined again like we have defined here. So that's why it is printing. Now, if you see the default, if I make a call to the default constructor without passing this arguments. So it is going to throw an error because we have not created model and make it the default constructor. We have commented it out, right? So if you uncomment this, okay? And you put in blank values, so stating that they are blank, okay, then you're going to get black. Okay? So okay, model and make self.age model,, self.age, speed. And what is missing over here? Underscore, underscore. I NAT, underscore, underscore. Ok, so missing two arguments, positional arguments model and make. Carter's equal to car. So it is not able to recognize the default constructor. Okay? Okay. Why that is happening? Because you cannot have two functions with same name, right? You can only have a single. Constructor here. So we are going to comment this out. Ok. It's unlike Java where you can have multiple constructors. Here, you cannot have multiple constructors. Ok, so we'll set the model here. Toyota and Lexus. Okay, so if I printed now, it is going to print out correctly. Ok? So it is going to create a model, create a make, create a speed. If you miss any of these creations, variable creations, it is going to fail. Ok? So because those models variables were not created. Okay? So that is, that's, that's the basic idea. And you cannot have constructor. So two different constructors to constructors with different parameters, that is not possible, okay, in Python. Now, another thing is now you, sometimes what happens? You don't give the model and make, you want to give some default arguments to it. Ok, this simply acts like a, so they say Toyota, okay? And make as equal to this is like your default parameters, like in your functions, okay? I say Camry. So this is the default because probably most of the customers choose to buy Toyota and Camry. So I set them as default. Now if I don't give these arguments, see what is going to happen. It is going to work out for us, right? So it is going to say Toyota and crime rate. So how is it working now? It is working similar to your default constructor with no arguments, okay? So that is what is no arcs constructor. And if you are defining a constructor with no arguments, you can also define default values to these older members, and it is automatically going to dual stores. Ok? And of course, you can call functions, okay? You can have more or less equal to Toyota, Okay? And make as equal to Lexus. Okay? So it's going to work Toyota and Lexus, and the current speed is equal to 0. So when you're actually creating your APIs or when you're creating your own classes, okay? So you can specify n number of parameters. And all those parameters could have certain default values. And you could give the documentation as well here. Okay, so how do you define your documentation? Just like we defined for functions triple. And then these are all doc strings. You can, and this is my car class. And you can define all the, give all the documentation here. And you can use the guidance document generation tools or third party document generation tools to generate the documentation for this class. Okay? So this is what is your so 0 arguments constructor. You have seen arguments constructor with arguments you have seen and you have seen default argument values. So when you actually provide default argument values, it could also act like a no argument constructor where you don't actually need to provide any parameters. Ok, so when you are actually writing your own classes. Make it as user-friendly as possible by itself being so user-friendly. So if you make your own API more user-friendly or your own libraries more user-friendly, it would be really great. So that's what is the basic idea of using Python, okay? And the next thing is variables. Ok? Now there are two types of variables, that is instance variable and class-level variables. Instance variables are variables which belong to a particular object, okay? When you instantiate a class C, let us say here, okay, now I instantiate another class, c1 is equal to car, okay? And now say model is equal to, it could be, say bends, okay? And make something X, Y Zed. Okay? And so this is what is I have to give the signal. So Make is equal to x, y zed, okay? And c1 dot info, okay? And if you see if a print ID of c1, okay? And if you print ID of c, they are, they are two different objects, ok? You will get two different ID locations. Why? Because there are two different variables, ok? This is c1, which has different set of values, and this is C, which has different set of values. So these are two different memory locations. And the model and the mean of these two classes have, are different. They have their own model and make okay, that's why they're called.'s class instance level variables. Instance level. Okay? Instance level means each instance with whatever you have instantiated would have its own set of values. Ok? You can change those values and it is not going to affect other instances are the objects of those classes. And so how are they? How do you quickly understand whether it's an instance or instance? It will have a self.age. If there are variables with, then they are all instance level. And if you forget to add self, then what will it become? It will become a local variable, okay, so that you have to be very careful about. Now you have understood instance level variables. Now what a class-level variables. Class-level variables are variables which belong to the entire class. That is, that particular variable is shared by all the instances of that particular class. So how do you define a class level variable? Say for example, for a car, you could have a class level variable like total number of cars that are manufactured, total cars, let's say. So. I would just say total cars is equal to, let say, a 100. Okay? I just give a random number. Now. How do you, how do you basically use distorted guards? How to instantiate or change this total guards? So as you instantiate new objects, that total car should be incremented, right? So that is what you need to do. So what you can do is you can say card dot total cards plus is equal to one, simple as that. So this has actually been instantiated outside the underscore NAT with an add the class level. And you have fused the car scope itself, ok, not the self dot because it belongs to the entire class. So, and now what you can do is so you can just put in total, okay? So, and total costs is equal to three, okay? And I just give here self.view, not-self, right? So it'll be card dot, okay? Total costs. So it just sort of, it's automatically coming. Now, if I execute it, see the first time the first car got executed, okay, instantiated story. So it will have one naught one because it is going to get incremented. Second, current students, it will become one naught two, right? And if I, let us print it out and see first. So if you see now, so you have total cards as well, not one. And for the next instance of a class, it has become more not to. Now, this one naught two will be shared by all of them, right? So after the increment, if I say print c dot portrait cards, okay, I can also call this at the end using the instance variable on. So that's one more very interesting thing. Okay? You can either call by gar dot total cars or you can say c dot total costs, okay? And if you execute, it has one, not 2xy it since it has, it is shared across multiple objects. Ok? So it is going to be same value for all the instances. And so the moment the next instance has incremented it, it is going to be shared across, okay? So it is class level variable. That's how we call it as a cluster of available. Now, there is an other way of actually maintaining these variables, okay, using the tag called class material. Okay? So how do you define that tag? So I'll just show you, so you just say add class method. So that means you are defining a method at the class level. So this can be called at classroom class method. I can deaf increment total cars. And automatically it has put in CLS instead of self-rate. The CLS is nothing but at class level. So how can you access the total costs, CLS dot total costs, okay? Plus is equal to one. So you can call it at the, at the class level. Okay? So this is how you call it at the class level. And what you can do within the class level, what are the variables that you can access? You can't access the instance level variables, ok? You can't say Self anymore here, right? Because it does not understand Self. Model is equal to something, because it does not understand self. Ok, it only takes CLS as a parameter. And using that CLS only, you can actually access all your static variables. Static variables are nothing but your class-level variables. Instance variables. Class-level variables are also called as a static variables. Now how can you call this increment? You can actually remove this and you can say card dot incremental gas, that's it. You don't need to put CLS v. So this is also going to have the cmd seem impact. So if I executed now, so now what happened the moment it is instantiated one object, the car dot incremental design at class level method is called. How is it? How does Biden understand it's a class-level method because that is an attribute at tag associated to it, stating that it is a class method and you have a similar definition as an audible method. And it is going to have C elicit, instead of using the CLS, you shouldn't be able to access all the static members, all the static methods, all those things can be access just like yourself. Okay? So, and yes, of course, there is another important thing you can call self.age variables and also methods. For example, self-taught accelerate, I can call here, I could specify something, yes, it is working here. So you can end similarly. If you want to call static, then you should use a the CLS in your static methods, okay? Or use the name of the class, OK, total gas. So this is how we have to use it. So I hope you have understood this. Now, in the next lecture, we are going to talk about namespaces and method types. Okay, see you in the next lecture. Bye. Welcome back. 33. Section-3.4 Classes Part C: Hi. In the previous section, we talked about variables, basically the instance variables and the class-level variables. How do we create class-level variables and class level methods, ok. We have understood all that. Now in this class, we are going to understand the namespaces, basically the class namespace and the instance namespace and the methods, the type of methods that you can, you should be writing in your classes. Okay, so let's go with the namespaces. So what is this namespace? So in namespace is nothing but the scope of a particular variable. So if you have here we have two types of variables that we have defined, right? We haven't defined a class level variable and we have defined the instance level variable. A class level variable will not have any anything like self, ok, and the beginning self dot. If it has self dot, it means it is an instance level variable for sure. Ok? And if a class level variable has something like CLS dot, okay? If available has something like CLS dot, then it is a class. It is surely a class-level variables, okay? So all the classes would be sharing this particular class level variable. That is why the namespaces basically a class-level namespace, that simple, okay? And all other variables which have self dot, they are all instance level variables, instance namespace, they belonged to instance namespace. So you have to remember that very clearly. I'm going to repeat to you again, any methods, any members which are starting with self-doubt or methods which have self, OK, so which have the first attribute itself. They are all class. They are all belonging to instance level, okay? Instance level namespace they all belong to, okay? Even your methods have memory locations, okay? Remember that even your methods, and of course your properties or your attributes, all your members, they have memory locations. And the second one is class-level namespace. Done now that you understood instance level, instance level namespace, class-level namespace up variables which don't have anything like self.view, but could have CLS dot ok for class level methods or it does not have anything. So those are all class-level methods. This is a namespace, ok? Now these concepts have to be clear. So you're repeatedly tried to understand this concept, keep it in your mind. It's great. Now you have methods. There are different types of methods, okay? They are instance methods called accessors and mutators. So as the name suggests, accessors are nothing but which are simply used for accessing your data members. Mutators, mutators have basically used for setting or changing your properties, okay? Changing properties of one or more attributes on a single attribute, okay? For simplicity, you could have single attributes, okay? And you have class-level methods. So you, How do you define the class level methods? We have understood it here, right? You have to use the Add class level tag, okay? If you use that adds at class level tag, they are all belonging to class level attributes. And the compiler expects you to put in CLS. And there are other methods called static methods, which also we are going to discuss. Okay, now let's look at accessors. How will you define accesses? This is a convention, okay? You don't need to follow the convention, but it is better to follow it so that you have proper accessors and mutators. And you have some methods which actually perform complex activities. That is how it should be, okay. So what do you, how do you access a nothing but getting the data right? So how do you define it? You say, let's say you want to get model, okay? So you say get model, ok, self. And you say return, self dot model. Don't forget self. Self should always be used right? And deaf and other accessor get, make. Ok. Again, it has come, our editor has put himself returned. Okay. Self-taught make. Okay. So these are all accessors. So how do you call them? You can just say C dot get model. Okay? And C dot get make simple. So if you execute this, you are going to get Toyota and Lexus. So you can have different set of variables, all these sets of variables you can actually access using this. Now, these are all called accessor methods which actually returns certain attributes. Okay? Now you have mutator methods, right? What am mutators? Mutators us setter methods basically. So how do you define it? Set model. Okay? So you're actually going to specify the model. So here, OK, model. And you say self.age model is equal to one. Okay? And if you can also make, set make, okay? Self.view make. Okay. And self dot make is equal to, sorry, this is self. This should not be there, right? Self comma meek and musical to make. So how do you set these things? So if I set it here, c1 dot or C dot set model is equal to, I will say Toyota. Okay, I have put this as hardware, can put it as bins. Okay, thens, because we are modifying this one, right? So we can see the difference here. So bends and something. Okay, u, v, w, some value. Oh sorry, model. Extremely sorry. So we have to set, right? C dot set make. So this will be controlling said something. You think, that's it. So these are all your, so first AS these are your accessor methods, these are your mutator methods. And if you see now, we will have, it has changed two bends and uvw, right? So this is how these are the basic things. Now, the next part is basically class methods. Class methods, how do you call? So you call the class methods using at class method. Okay? And there is another method called instance methods. Now how do you call instance methods? Instance methods are simply called with at instance. Okay? Add static methods. Static method, okay? And deaf. Let us say something, something which is not relevant to any of the data members. Like you want to initialize something, okay? So you want to basically initialize something else which does not belong to this class properties. Okay? So something like your database connection pool or something like that. Okay, so gone pool size, something like connection both sides to a database. So I would say 1000 connection pools. So what do you say here? Def set, initialized, initialize pool or something like that. See here, it does not give me the CLS. Okay, it automatically does not give me the CLS. That compiler also does not expect any CLS because although it is a class level variable, it is class-level method. It is a static method. That means it does not belong to any of these CLS or any of these things. Okay? So you can say, pool size is equal to something. And say here all I would say SIS ID and I can put it as SSID initialize. So basically what we are saying, oh, you could use CLS also here also, you could initialize it, see if you want. But CLS dot, ok. So what does it con pull size C. It is still available here, but we don't want to do it like that. We want to maintain another method which is called static method. And we want to call it at the static level only. That means it is something to do with variable which is not a property of the car itself, but it is some other property which needs to be initialized, maybe probably to access the data from a database or set some pooling parameters or some kind of internal parameters for your getters and setters. Ok, so probably you're using this con pull size to connect to a database and fetch the data when you're making or when you're setting. Okay? So basically since those kind of variables or those kind of properties you can set using the static method. So that is the difference. So if you put it clearly, even it is going to be very easily understood by the person who is actually reading your class. I'm trying to understand your API, okay, so that is why you need to use these methods correctly. Ok, static class method and static method class method is basically for class-level properties. Static method are properties which do not exactly belong to the class, but they are some kind of helper properties which are used, used internally by the class. Ok, so that is one. So I hope you understood your classroom methods and static methods. Now, in the next class, we are going to talk about another interesting concept called inner classes. See you, bye. That said, there are. 34. Section-3.5 Classes Part D: Hi, so till now we have got a good understanding about classes, like how to define a class. What are the variables, methods, how the memory is allocated? What does the importance of self? What kind of constructors you can create, okay? And that is your 0.5 argument constructors, constructors with arguments, constructor with the default values. And then you have defined variables, namespaces, and you have method types. So basically this is a convention I can say. So you want accessor methods to access certain properties. You want mutator methods to change the properties, and you have static class methods and you have static methods. Now finally, we have inner classes also. Okay, this is a very interesting concept. Now, what are these inner classes in the classes are nothing but classes which are defined inside a class. You can nest another class inside your class. But why would you want to define a class inside a class? So that is the thing that you want to understand. Say for example, you want to define a class four. Chances are, chances is nothing but your body or the main, one of the main components of your car, which actually contains your suspension, your exhaust system, and your steering box, which actually houses your complete engine, right? So now this chances has no importance outside the class go, right? If you actually define something like chess is here, see hedge a SSIs, ok. And I say pass, I don't want to define anything right now. So what if somebody sees this, that he would, he wouldn't really understand. So which is this is this chances for a car, this is a chess is for a truck. This is a chess has fought an aeroplane. Nobody understands, right? So that is the reason why you would actually want to define this inside a car. Okay? So you define the chair sits inside your card. So what happens? You, people who are actually going through or reading or understanding your API, or actually using your API, would understand that, yes, this particular chances is inside the car class, ok? And this chest is class. So it actually represents the chances of a car. Okay, so here you can actually represent all your parameters. So what do you say? What do you do here? Def underscore, underscore. Underscore, underscore. Okay. And self. And I can say self dot all your distinct, okay. Suspension, Okay. And something some value for suspension as USB, y1 and y2 have self.age exhaust. What kind of an exhaust system that you have? Okay. It's, it does itself could be another object and other complicated object. Okay, self.view, stealing box, sitting box, I'm assuming they are basically simple string battery does. Okay. And you can have getters, setters, you can have different kinds of different kinds of methods for changing the sort of form, making calls to these, or for servicing what kind of operations that you want to perform, etcetera, etcetera, all these things. Now, what would you do here is you would actually define a chair says, so it's would say self dot CHA, SIS, CHA, SSAS, okay, is equal to chess. So it can directly define your chest is like this. So CHA SSIs, Yes. So why is it giving us unable to resolve the chess? So I would actually define it here. Okay? So if I instantiate this, let us see. If I instantiate this particular Celsus. How's it going to work? Justice is not defined. So how would you define that? You just see card dot chess, right? So that's how you define it that beats within this card class. You're actually going to define this otherwise, or otherwise, how would it work? You'd have to define this chess is outside the scope. Okay. I'm showing each portion so you understand the score passive, you understand the material. And so if you had defined as outside, then you don't need to put this card dot, okay? So the disorders such as Kant dot chess is, so this is how you can actually instantiated. And another way of instantiating it is say, if I say S3 as a CTO car, okay? It is not going to give an error because it is having default parameters, right? So it will act as if it's a no argument constructor. I'm just showing you here again. Ok. This one. Now, if you say Celsus c, which is equal to Carre d'art chess. So this is how you can also put it here, okay? So I can just print the type of CH If I want. I can see what kind of type this particular cluster C, It has a car dot Chester stack. So that is how it is. Okay, this is simply what does interclass. So when you have complex objects, okay? Blueprint and object blueprint, which actually has some more sub blueprints, okay? Like a card has a chances. And the chances itself can be represented as a blueprint by itself. And it can be associated only with car. Okay. Or each type of objects like cars, trucks, each of them would have its own chances. So it is best to represent it as an inner class, okay? And it is in a class would have its own attributes and how to instantiate it. You would instantiate it using car Dorchester is that as the class name in the outer class name dot, okay, that lastname and bracket open bracket close, or the object that you have created, DHSS when you're instantiating it outside, okay? So this is basically how you have to represent your objects. Now, you should also understand C. When I have defined the chair says, please look at the indentation that I'm falling. So I'm falling for spaces indentation 12341234. So here I have defined the class. So the top level class has no indentation. Okay? And all the methods in the classes members definitions have an inundation of Ford and all the statements within their particular method. They also have fought in addition, so this is how I am working. Okay? This could have to indentation if you want, but everywhere you have to maintain two, ok. So you have to maintain it too. So it's better to have uniform Ford indentation, which is the default inundation. And this is how you write it, okay? And that's the advantage of using editor. If you use a notepad or any, anything, you would never understandable if you had any kind of indentation issue. Okay. And the ID takes care of issues like dabs and whitespaces. So some places if you have use dabs, in some places you have used whitespaces, then the inundation will not paid them a lot. Compiler not accepted. Ok, so you'd have to follow a uniform approach that is either tabs or whitespaces. That's why I suggest you use a proper editor. Don't try to write this things in notepad. You could use Notepad Plus, Plus if you want, but don't use Notepad or simple editors MCAT it as well. You don't understand the indentation, okay? Where the editors don't understand all those indentations for byte. Ok, so now we have understood the basic concept of class. We're confident and of how to write our classes. Methods, variables, okay? You know, different combinations and permutations of variables, methods, whether they are static methods, whether they're class-level methods, where they are instance methods. Whether you have class-level or static variables or you have instance level variables on that stuff you have understood. Now in the next class, you're going to understand how to coordinate different classes, okay? And how do you use inheritance, the concept of inheritance. So see you in the next class, next lecture. And also I request you to complete exercises on for each section before going to the next section so that you get a good grip of whatever has been taught to you so that you are well prepared for the next subsequent lectures. Thank you. See you in the next lecture. Bye. 35. Section-3.6 Inheritance and Polymorphism Part A: Hi, in the previous classes, in this section, we had a detailed discussion about classes. Now, in the subsequent few classes, we are going to discuss about inheritance and polymorphism. So if you remember in the first class or lecture on the classes, we have said that each class is by default going to inherit from object, the buttons object class, ok, if it is not explicitly defined that it is inherited by some other class, it is always going to inherit from the object class in that scenario, right? Now, what is the meaning of inheritance? Inheritance means it is going to acquire all the attributes and all the methods of that particular class. Ok, now let us take an example of where we could use or what is the significance of this inheritance. Now, we, in the previous lectures, we have defined a class called car. Ok? Now let us say some other developer would like to define a class called Truck. Okay? So I'm not going to implement it right now. So I'll just say pass. And, and another developer would like to implement class called Flight. Okay? Okay, and, and so on. Ok, now, we already have a card class now. So if you see each of these struck flight, all of them have certain common variables. Okay? Like me can model and common set of accessor methods like get made set, make, get model set, model exedra, right? So you'd have to redefine all these methods in each of these individual classes. Okay, so instead of doing that, what we could do is the best way would be have another class called vehicle vehicle. And then you could have you could define those. Make Anne Morrow. Okay. So I just put him make a sequel to this model as equal to this, okay? And then self.age make as equal to make. Okay? And self.age model is equal to or, okay? Now what I can do, I can inherit this particular vehicle here. Okay? So what is going to happen now? Remember the pass right now. So it is actually going to inherit this make and model. Okay, here also I am going to inherit. So now if you see OK, so I'll say, let's put in as default here, okay? Okay. Now, if I say D is equal to truck, okay? And what I can do, so print p dot, make, okay? Print d dot model. Okay? Similarly, I can have flight, physical to flight. And remember this is case sensitive so we have to put it correctly. And then I will again print, okay, f dot make and print f dot model. So let's see what is going to happen now. So we'll have to first execute this and inheritance. So you can see default, default has got printed. Why? Because we have set. So these are, I can put in a print here. Print. Ok. So if I execute now. So the first two defaults are for your truck and the second two default rate. For this, that means automatically the make and model got initialized using the constructor. And at the same time what happened? See we have not defined any constructors. So it has called this constructor by default. And it has initialized the variables to default, okay? And it has printed. So just to buy inheritance, we are able to acquire the attributes, make, and model. Now how about your accessors and mutators, right? You can actually have set model, okay? So self coma model, and I can say self dot model is equal to model, ok. And similarly, DEF set make, make, okay. And self dot makers to make, right? And then at the same time I can put in them accessor methods, that is get model, ok, self, and that's it. We're not going to do anything here. I'm going to just say model. We have forgot an L here. So there's a spelling mistake. Okay? Or returns model, right? Self.age model and Deaf kit make. So we have return self. Dot make. Okay? So now what happens? Even these methods can be called here. So that means for the truck, I would say D dot set model C, it is working automatically. The ID is able to pick it up CIT model, okay? Truck model, okay, let us say and then d dot set make, okay? And then I will say truck mic. And similarly here, F dot set model. And they see flight modern, OK. And f dot set make and flight make. So no what happened? We have actually corridor barren classes, get model set, model, get MakeSet, make, and we have virtually not implemented anything in the truck. So all of it has automatically got camo has come out here. I can see here I can call the accessor methods right? Get model or to get, make all that stuff. Okay, get me and sorry, get make the same thing here. So I can say dot, get, make, and get model. So now what is going to happen? So fussy, you have so Truck, Bottle, truck make. And then okay, here I have to make one of the myths may create make or this will be model. And this would be make. Okay? And, and this is going to be okay. So if I execute this, so you have flight my mic, flight model, and we have truck model and truck mic. Okay, so that means what have we done here? We have not implemented anything. We're just instructed the compiler seeing that the class struck is bare and has aberrant wake, ok. And similarly the class flight has a better vehicle. So this is how the definition of inheritance works. Okay? Now, if you create any of these methods, now let us go to the next one. Okay? Now, automating the constructors, you want to overwrite this constructor literacy. So you have ordered in the constructor here. So I would say this, okay? And let me copy this whole stuff. Okay? Now, what I'll say here is and synthesis first as make, late truck make and model. Ok. And similarly, I'm going to put in here as well. So now what happened here instead of Make, It will be flight mic. Okay? And flight model. Flight model, okay, so now I wouldn't do all this. I will initialize this, let us say. So what would happen now? I remove this and I do this as well. So we have simply initialized truck. This is going to call the constructor. This one, ok. It does not go into colder parent constructor. Why you just weren't going to call the parent constructor because you have already overridden the constructor. That's where it is automatically going to call your bed and district, and that is what is called as a constructor overwriting. Now let's execute this NC. So if you're executed decency See you have truck models, drug made, truck model, truck meek, and flight model and flight make. Okay. So it has used these two constructors automatically, and it has said that before in properties. Okay, similarly, you have even this. So let us even a further method. You will have overriding and it'll say I'll put it in another one called info, ok, self. So print. This is a vague, okay. And I override this muttered inflow. Yeah, I remove the sparse. I don't need to pass anymore. Okay. So I will say this is struck and this is Flight. Okay? Now, if I call this method, let's not print all these things now. Okay? And I just say print d dot info, ok? Similarly, i call print f dot info, F dot info. And I come into this our decimal. So let's see what happens now. So you can see this as a flight when f dot info wars cold and what happened for the truck? Let us see. Stop. Andrey runs Saudi. Okay. So this is a flight entices truck. So what happened? Vk called info on a flight object, and it has called this one, it has not called the parent. But if I come back this up, that is if I don't have an overridden method for a flight. So what would happen? It will called the parent metal automatically this as a vehicle. You understood rate. So it has called this one. This is a vehicle. So if you have a method which is of the same name as its bear into class, then it would overwrite that. So that is what is called as overriding. So that at place for your constructors as well as her methods. So that's one thing you have to remember. Okay, now, in the next section or in the next lecture, we are actually going to talk about calling the parent class constructors. Okay? See you. 36. Section-3.7 Inheritance and Polymorphism Part B: Okay, so in the previous class, we have talked about inheritance Howard has defined. So you have to basically use brackets and the class name, the bed and lastname. And what are the advantages of using inheritance, okay, and then you're also, we have also talked about overriding, ok, now, the advantages of inheritance, if I may speak, speak out, then basically you have less amount of coding, less amount of maintenance. Okay? So you're writing the cold, all the basic chord, the accesses, the mutators, the constructors, everything in the parent class, okay? And only the specific functionality of a truck or a flight is going to be added in, in their respective classes. So this reduces the coding, makes a code more maintainable. Okay, so that is the advantage. Now, let's look at calling the parent constructors. So we have understood how to call override the constructors and methods, right? So in the child class, you can basically create method with the same name and it is going to override the parent class method, right? Or the constructor. The same applies to the constructor. But now you would want to explicitly make a call to the particular constructor. So when do you really want to make that particular chord, okay, at, in what scenario would like to make that call? Let us say we have a static variable, ok, so this is going to be Vehicle count. Ok. It'll count is equal to 0. Okay? Now you want to increase the vehicle code so that this vehicle dot vehicle count plus is equal to one. Okay? And then I would say get vehicle count, I will actually defined deaf, okay. And get the vehicle cup, which I see Alice vehicle, car, right? And then, so this is going to be a static method, right? So I'll write it like this. If this is going to be a class method, static method, class method, right? And deaf get maker count automatically going to give me CLS, okay? And I will see CLS dot ok. So directly and making a call to this guy. Now. So if you want to increment the vehicle count, you will have to explicitly call this constructor, right? Otherwise, it is not going to increment. So in this scenario, if you actually say print the vehicle count, okay? Of course the vehicle counters as a static member of vehicle, right? So I can just call it directly using the vehicle dot equal counterweight Eigen, say vehicle. Dot com. So it is always going to be 0. Okay? Why? Because we have not call the super constructor. So that is the parent's constructor. Only the parent's constructor can actually increment the vehicle count. So this is these are the scenarios that is where you would want to call something in the superclass's constructor, okay, to explicitly set something, okay, which is, which is going to get reflected down to the child, changed losses as well. So in that scenario, what you're going to do, you're going to call a special method called super, okay. Super dot. I can call underscore, underscore ID. And I can actually pass the make and model directly. And also another thing, No, the truck class, if you see, has got its own meek and model right? Now, you see here you have vehicle class also, which has the flightless also which has its own makeup model. So we're going to remove these things, right? So we don't want to have separate members are going to remove this, okay, and make a call to the superclass, that is to the parent class and call underscore, underscore I NAT. And we simply pass the make and model to this. Okay, models with this. So now what happened here? Now, let's see, when you are instantiating a truck, you have instantiated a truck, Okay? Then what happened? It has actually called the initialized method where the default parameters have been taken because you have not provided the values. But now you don't have any variables or any properties of the Struck defined here. So I removed this. In fact, it is actually going to be directly passing this modelling make to the superclass constructor. The superclass constructor is going to set the model and make and also incremental vehicle code, right? So that is how it is working. Now you see it has been totally simplified itself completely. So you have no attributes which are relevant, common attributes which are relevant to both truck conflate defined in these classes. They're all defined in the superclass. So all the functionality is going off into the superclass, does nothing much in the base class. So this way, the base class will only have the functionality, the bare minimum functionality that is required these classes. And it should not have anything else, okay? So that is how you maintain. That makes your code more maintainable and more clear to your developers and your work uses as well. So now let us execute and see what happens. Now. See, first thing you notice the value as to afford the two is vehicle count, the last print statement. Okay? And the second thing, this is a vehicle, this is a truck, let us say now we can actually print out. However, modelling make, right? Modelling make and modelling meek. And I'm going to put in our start as well here. So to make it clear here, so what should it print here? This should print the model and make properly here. And the model and make properly or here as well. So if I execute this, see this is a flight model. Okay? There's a flight model which has come out correctly. And this is a truck model which has come out correctly. And another thing that you notice is the vehicle counters to the vehicle count has increased automatically. So what is the advantage of actually calling the super constructor? The mod? You can call the super constructor. You can push all the functionality of your subclasses to its parent class. So you keep the parent classes to its bare minimum. You will have almost nothing unless and until it is explicitly the functionality or fight flightless, you'll really need not actually called that. Okay, so that is the advantage. Now, in the next lecture, we're going to talk about multiple inheritance, wherein we are going to see how you can inherit multiple parents, okay? To the end, the child class and what other difficulties that you will face in such scenarios and how do dissolve those difficulties. Thank you. See you in the next lecture, right. 37. Section-3.8 Inheritance and Polymorphism Part C: Hi. So in the previous class, we have understood how to call the parent class's constructors. Ok? The same applies to methods as well, just by using the super, okay, we have not covered that part. Apologies for that. So you can actually use super AND also called the parent classes methods. Ok, so that is also possible, like for example, super dot info. And you can simply call this method. So this is actually going to make a call to the parent class. You don't need to pass the selfie or you can directly call it. Okay? That is also possible. It is similar to calling a super dot in it. Ok. So that's, so when would you call the super method? Methods where it seemed similar to the scenario of super constructor. Where do you are doing something which is going to be impacting some genetic aspect of the truck that does genetic aspect of a vehicle. That is when you want to call the super, you wanted to increase something or they want to make a change to a variable that is specific to though bagel, all that stuff. You can do it using that. Okay, now in this class, we are going to actually talk about multiple inheritance. So this, whatever we have done till now as single inheritance, that is, each of these classes, that truck class and the fight class have actually inherited only a single class. They all have inherited on near things lasted as vehicle. Okay, So they are all single inheritance. Now, in case of multiple inheritance, how do you inherit? Okay, let us first come into dalda scored. So to make it more clear. So you can select all this, go to coding and combined with a comment with line coming. So it's going to come into top completely. Just going to push this down a little bit, so it's clear for us. Okay, now let's create another class called flight capability, okay? Okay, flight capability, which is extending object, did not even say that actually. Ok. And then we say def underscore, underscore init. Okay. And parts. I don't do anything. And the flight ready. Okay. Now, I want the flight has gone to flight capability, right? And so I would want to extend this as well along with the vehicle capability vehicle. So what they do, I just put a comma and another class. So now this is gotten by dividend returns because why? The flight has to parent classes, it has inherited. So it is going to take the methods from its parent classes, board dispelling classes. Ok, so let us look at a few examples and see how it works out now. Okay, so let's put in a print statement here, that boss and say, okay, this is this is flay capability constructor. Okay, now I Dick sprint statement, complete here. I call it here also. So this is Flight constructor, right? Says flight construct. This was going to be the first line I wanted to put in. And I'm also going to put in vehicles construct. Right? So this is the first time this is where he could construct. Now, what has happened now? No, I have actually, you find initialize a flight than underscore, underscored INA d. That is the concept that is going to get caught, right? And it is going to make a call to the super. But now we have two parents. One is the flight capability and others though, vehicles rate. So will it make a call to vehicle and bought the flay given median vagal? Odd will it call only the first? Let us see that we can do this Barstow because we have implemented the flight. So f is equal to flight, right? I'm not passing anything here. Now if I execute this statement. So what happened? It has current a vehicle constructor and it has Calder flight constructor. So what happened? So when we have initialized this, it has automatically correlate the top-level constructor, the vehicle constructor. And then it has gone down and it is called the flight constructor. So it has not quantity or flight capability constructor. Ok, now let us comment this out and see how it is going to work. I'm not going to call the super here. So if I execute this, it is only going to call the flight constructor. That does only this one. Okay? So what it means is you have to actually ok, uncommented it out just to show you. So it has Card the flight constructor first. Yes. It has printed the flight constructor. Then it has called the super the soup, but has called Only the vehicle construct. Oh, okay. It has not called the flight capability constructor. So haunt how how how does, how did this happen? So if you analyze this, if you see, I just put in some comments here, my delay and comments just to show you what is happening. So the first superclasses where he got great. Okay? And the second one is your flight capability, right? And in the middle, that does your flight, right? And so the flight Does extending the vehicle and flight capability. But if you see it has only called the constructor. That is on the left. It is not called the construct of the descender, right? Okay? So when do call the construct on the left, on the right, if that particular vehicle does not have a constructor at all. Okay? See, I put a multi-line comment here, okay? And I put this whole thing in a comment. That means you don't have any constructor. The vehicle level, okay, and it won't deconstruct. Now you see what is going to happen. Ok? So now I have to, so what has happened now? So it takes one positional argument, right? So what I do, so poor. I remove these two because there's no constructor that has no listing rate. So now if you see so it is called Flight constructor, then it is called flight capability constructor. That is since the init is not existing or here, it is actually calling this constructor. That means the first preference is to call the constructors on the left side and then to call the constructors under the light side. So that is the way it actually functions. And now another thing that is very important is if you don't define any constructor, it is going to create a constructor with a default to 0 argument constructor. So what happened here when we actually put in the model, inflate, weighted it through a compiler at all. Because this constructor does not exist in flight capability, right? It was existing in vehicle, but we come into doubt. So it thought, Okay, let me call the superclass bacon. Inside, there was no constructor. Then it went and tried to call the constructor in flight capability. There also did not find this constructor. So I removed this. If I remove this, it will assume that it has a default and no argument concert and it's going to call that. Okay? So how do you let us define this constructor here? That means we will just say model and make, okay? Coma model and coma make, okay? So we are not using this modelling may constructor here. So if you call it now, it's going to work. Okay, so first what happened? The flight constructor got caught. Then it tried to call the vehicle constructor with modelling make, but couldn't find the vehicle constructor. So it went in and colder flight capability constructor. Ok. So that is how it is. Now, how do you distill what happens? No. No. Let us say if you have defined any of the methods sulphuric No, let me revert back. Let me remove this constructor. So what happened now? Okay, let me put this construct them back. Effect. Okay, I put this constructor back. Now what happens? It is going to call on Lido, construct a rate. We can construct a. Now, if I had defined any variables in the flight capability constructor like self dot ok, speed, flight speed, okay, is equal to 0. If I define this. Now what would happen to self.age flight speed will not get reflected here. Because this, if I say F dot flight speed is equal to ten, if I say this, then what's going to happen? It is going to throw me an adder. Apologies what has happened now. It should have called it called the vehicle constructor. But then, okay, it has defined a new variable here, right? It has defined a new variable called flight speed, but it cannot print this flight speed, right? If I say print f dot flight speed, it is going to fail. Right? Because the flight speed object does not exist. So when you said F dot flight speed is equal to detonate, created a new flight speed attribute for the flight. Ok. But now this flight speed, being a member of this, it never got called. So that is the problem. How do we get rid of this problem? We get rid of this problem by actually defining a default constructor in both the cases. So we can create a default constructor. And we, this can be called as a default constructor because it has attributes and we remove this. Okay? Now what is going to happen? Okay? Now, if I execute this, okay? Executed this. So what happened? Now? It has said the flight constructor and the vehicle constructor. So let us see what happen now. So how do we get around this problem? We need to make a call to the default constructor. Ok, so this will make it a default constructor call. Let me show you in on the parent and child classes. Okay, so chain and as for less than the parent class. So let me put it here like this, okay, it properly. And in addition, now what is going to happen? You see, now it's going to call all the constructors. So what has happened? Let us see. Now, it has actually called the flight constructor. Then it has called the vehicle constructed, and then it is called the flight capability construct as well. So how did this happen? So basically how would this working? Is it just going to give preference to the left side one on the left side glass, that is the vehicle constructor. Ok. So it has called this constructor, fine. Now, if the, if the constructor did not exist, it would acquire this. Okay. But then here in the vehicle constructor, you have call the super constructor, super right, Superdome and equity, which means it is calling the object. So it is something like objects, objects i and 80 method right now. So on top of it, you can just say that it's an object. Here. It tried to call the objects cyanate, but the object I NAT does not exist. So what it did instead, it called the flight capability. So this is how you will have to call. So basically you will have to call the init default constructor. So if you make a call to the default constructor, it does going to fourths fully call all the constructors. That is all the parent constructor. So that means from here it is going to call the flight as well as flight capability. But you know, this is a lot of confusion. So calling multiple inheritance. So multiple inheritance is there and sleeplessness instead and Biden, however, it's not that in Java, okay? Because it kind of creates lot of confusion. So the best thing to do is to have a single parent. And you couldn't use interfaces and abstract classes, which we are going to talk later. So besting you'll remember as it would have done this, just how one inheritance. So which makes it easy to understand. Otherwise it is going to become a big medical down and it will never be clear to you. Okay? So we have understood our multiple inheritance as well. How you define your multiple inheritance, how the parents constructors get card, okay, in the next lecture, we're going to talk about polymorphism. See you in the next lecture. Bye. 38. Section-3.9 Inheritance and Polymorphism Part D: So in the previous lecture, we actually talked about the multiple inheritance. Okay? Now in this lecture we are going to talk about Polymorphism. Polymorphism means something which takes many forms. Okay? So we're going to understand how the definition of polymorphism, the basic polymorphism. And then we look at operator overloading, method, overloading and overriding as well. Ok, so we will see overloading and overriding. Okay, so let's comment this out first, okay, so that we don't get into too much of confusion. So just go back to code and I'll just say come into DOF. Okay? So the comment, everything. Now, now we look at definition of polymorphism. Let us say we have a class which extends object and we have info method in a token info, which basically prints, prints, and Plassey. Ok. Similarly, I have another method, class B and class C, which has similar kind of populations. So I say class B and see, I just change this to Class B and Class B and Class C. Okay? Now, if I just see x is equal to a, okay? And print x. In fact, I don't need to use print x dot info. Ok. Now the C mix I'm going to actually put into B. And I will say X dot info, okay? And again seem x where to put NFC and X dot info. So what would happen now? Let us see. So if you see it is calling, I'm calling, I'm glassy and class B and class C. So this is the part of Bitcoin, okay? So it is the variable or is nothing but just a DAG, okay? And this DAG can be pointing to any type of a class, any type of a variable. And based on the type of class or variable that is stored in that memory location that is pointing to this particular tag. It is going to call that respective operations, that particular aspect of operation, okay? And so that's the basic capability. So. And this is one form of polymorphism. The simplest form of polymorphism wears the same variable, could actually behave differently when it is assigned to a different variable. So this is not possible in C or in Java because you have to explicitly define a class available like a is equal to nu a or something like that. And then you can't change that to be unless a and B have some kind of a relationship between them. Okay? So otherwise, you cannot, if you do that, it is going to give a adder. Now, this is what is Polymorphism? This is a simplest form of polymorphism that you have. And the next type of polymorphism, which is another interesting part, which is there in C plus plus operator overloading. Okay? So if you see the simplest aspect of corporate law and learning, so let me remove this since we have understood. So if you have E is equal to ten, OK? B is equal to 20, okay? C is equal to a plus b and print c. So what does it going to return? It's going to give you 30 right? Now. If E is equal to hello, okay, with a space at the end, B is equal to pipe and OK. And if I say c is equal to a plus B, then what is it going to print? Print c. So it should show hello byte, write C. So in case of integers, it has acted differently. It has not said 1020, right? It has added them as ten plus 20 equals 30. Whereas in case of string, it has understood that it has to simply concatenate the string. Now, in case of list FEC, L is equal to K, one comma two comma three comma four. Okay? M is equal to say, 45678, okay? Now, n is equal to L plus M, OK? And if I print, and so I'm just going to append all these guys. It's not going to add the individual structures. It has actually going to append these 12345678. So this is on operator or loading. That means an operator would behave differently based on the type of the operands that you're working on. Okay? If, if they are integers or floats, it's going to perform mathematical operation. Otherwise a string operation of it as a string. Otherwise it is going to perform something on that list. Okay, so this is operator overloading. Now, fortunately, you could also use this operator or loading in case of, in, what do you say like when it comes to your own custom classes. Okay? So let's try to define some, create some real example. Okay? So I say class stationary. Ok? This is a class and it has definition constructor. Okay, and what DSA, self.age books is equal to 0, okay? Self.view enters is equal to 0. Okay? Now, deaf, Okay. What do I say? Def info, ok. And I say print. Number of books is equal to 0. Coma numbered off. Benton's equal to one. Ok. Dot format. Okay? Self.view books cover self.age benefits. Okay, now we add a method. Since it is, we say set petals and comma P. Okay? So this is nothing but as equal to be. Ok? And similarly, DEF, set books is synthesized to come here be okay. Self.view books is equal to b. Ok. Now what I do is now I instantiate and book stationary, okay? S one is equal to stationary. And then S one dot set books as ten, okay? S1 dot set rentals as 20. Okay. S dot info. S dot info isn't for not coming. S1 dot info, right? So let me just print this one. So you can see the number of boxes, ten, number of parenthesis 20. So we test printer it here. We have added two mutators. The mutators actually set the pencil and books, and you've got the value right. Now. Let's see if I have another video and other stationary object, okay, which is S2, S2, S2, S2, S2. Here I have and d, and this is 30. Okay? Now, if I print this, if I execute it, so I have number of books in S11, S bend and 20, number of books in S2, S Duan De and 30. But if I say print S one plus S two, what is going to happen? It is going to throw an error y because that is an unsolved subordinate operand type plus OK. So how do you overload your operator in this case? So what you should do is you should write def underscore, underscore all this. You can write. And okay, self and other, OK. And then what did should return? Basically, it should say b, return. Okay, so instead of done, what I will do is self. It say, I will say b is equal to S, is equal to stationary. Da, De, I owe any white. Okay? Now S, S dot Books is equal to ok, self dot books plus other dot books. Okay? And S dot fences as equal to self dot pencils plus other dot enters. Okay? Now, and then I have return s, Okay? So this is how you write the add operator. Now, in this case, what is going to happen? So if I say S3 is equal to S1 plus S R2, and I say S three dot info. And I remove this, I don't want to print it. Ok, so let us look at this. So you can see here. So it has added the books and pencils. So there is a operator overloading where it couldn't accept our user-defined stationary object. How did we achieve this? So you see here then plus 20 is 3020, plus 30 is 50. So we just come out very well. Now how did we achieve this? We have just return, underscore, underscore, add with self and other. This other could be a stationary object or it could be a different kind of an object, okay? Based on the type, you can actually take a decision. And in our case at a simple, Both of them are stationary objects. So you created a new stationary object and you have set the value of books to the current value of books. That is the s1's because that is this one. Okay? This one would actually be the self. And this to this S2 will be the value of others. If few C, C plus plus, you would readily understand it in C plus plus also you will use this kind of operator overloading. Okay? So this is where you actually dismissed the way you can actually do operate on learning. There are various other methods which you can actually look. So Boolean C, not known about these things. And, and Milan, so might be dead sea Molas there subtract as their self and other. And greater than, equal to, greater than or equal to, greater than. All the stuffs you can actually do. You can override operator overload. So when you overload these operators, they will behave accordingly. So just remember a point. So S1 dot. So this is equivalent to basically what you're saying is S1 dot. Okay, underscore, underscore, add, underscore. Underscore is two. So this is what you are actually doing. Okay? So instead of calling this byte and also the acceptor plus operator, instead