YTread Logo
YTread Logo

Python As Fast as Possible - Learn Python in ~75 Minutes

May 31, 2021
Hello everyone and welcome to Python as quickly as

possible

. In this video, I will try to teach you Python as quickly as

possible

. That means I'm going to go over things pretty quickly. I'm going to speak very quickly and keep in mind that this is not for absolute beginners. If you are looking for a series of tutorials for beginners, I have many on my channel. I'll link a bunch of resources below and if you think I missed something or made any mistakes, please leave. That being said, let's go ahead and get started and get into Python as quickly as possible to get started.
python as fast as possible   learn python in 75 minutes
We need to download and install Python. Download the latest version of Python from the Python website, which will be linked in the description if you are using any version of Python lower than 3.6 which will not be supported by this tutorial when downloaded. Check the box that says add Python to the path. This will make your life easier in the future. Python now automatically comes with its own environment. writing code in this is down, you can use it to write your code if you want, but I prefer to use Visual Studio code which is a text editor to download, you can go to the link in the description and just download the stable build. for whatever OS you are on now, if you are using vs code there is a bit of setup we need to do to get started here we simply need to install the

python

extension go to the extension tab here this will take us to vs code Marketplace we can type

python

and then we can see the python extension and just press install.
python as fast as possible   learn python in 75 minutes

More Interesting Facts About,

python as fast as possible learn python in 75 minutes...

You can see it for yourself. I already have it installed so before we start I thought it would be a good idea to talk to you about some of the things Python is used for here I'm on my channel under the playlist tab and you can see a bunch of playlists different playback, just to give you an idea of ​​some of the things I've created with Python and taught on this channel. A general purpose programming language, it is very easy to

learn

, versatile and really easy to write. The main advantage of Python is how simple it is, how easy it is to read the syntax, and how

fast

development is.
python as fast as possible   learn python in 75 minutes
That said, Python is mainly used on the web and in tasks related to machine

learn

ing, artificial intelligence and data science, now the sponsor of our video knows a lot about that and that's just life. I have to thank just learn for sponsoring this video and giving everyone a discount on their data. scientific master's program that was jointly developed with IBM. This program is comprised of six unique courses that implement a unique blended learning experience in a high-engagement online classroom environment. During this program, you will master over 30 in-demand skills and work with tools and languages. Like R SAS Python Tableau Hadoop and Spark, you'll master these skills through 15 real-life projects and one capstone project during this comprehensive 12-month course.
python as fast as possible   learn python in 75 minutes
You'll also receive $1,200 in IBM cloud credits to use during your 24/7 access. the ibm watson platform after completing this course, he will receive ibm certificates and simply learn to testify to his skills as a data science expert. Start by hitting the link in the description. I want to start by covering the main data types. In Python these are int float string and bool and they are also known as integers, now an integer or int is simply any integer that does not have a decimal point, so two three seven three seven was going to be an int minus nine , which is a negative inch some large random number is an int as long as it doesn't have a decimal point, we consider it an int, a float is almost the opposite of that, it's simply any number that has a decimal point, so something like 272.00 this is a float, although you can consider it an integer, the zero point adds a level of precision to this making it a float, of course something like 9.7 would be a float whenever you see a decimal point, which means the number is a float next we have a string, a string is simply anything enclosed in single or double quotes, we usually think of this as a sequence of characters or numbers, so if I type something like hello and I type something like hello, these two strings are actually completely equivalent, aren't they.
It doesn't matter if you use single or double quotes, it makes no difference. I will note that if you want to embed a double quote or a single quote in the actual string, you will usually wrap the string with the opposite type of quotes. so in this case, I want to have these double quotes inside the string, so I wrap the string in single quotes now just to keep in mind here if I do something like 4.6, although you could consider this a float, this is a string again because it is in single or double quotes remember the definition anything defined or surrounded sorry in single or double quotes next we have boolean this is one of the two values ​​that we have true or false some people can consider this and consider this zero we will see them more Go ahead and you'll see why it's important, but it's a boolean value and these are the four main data types in Python.
The next topic I would like to cover is output and printing. This is very important. and we'll do this a lot in this video in Python. There is a simple function called print. This is how you send something to the console when you run your program. Normally when you print something you put it in strings so I want to print say hello world so I'll print the string hello world like this and if I run my program by pressing this run button you can see down here in the console we get hello world now notice What if I just write hello world like this and don't put it inside a string and run my program.
I will receive an error. This is because I can't just print something like this. The program doesn't know how to interpret Hello World if it's not wrapped in strings. This is because of this. It's not one of the main data types and we don't have any variables or anything that denotes what hello world is. That said, if I want to print a number, say like 4.5, Python knows what 4.5 is because it's a float that you can see when I highlight. It says float if I run this it will print 4.5 and there will be no problem now if you want to print multiple things what you can do is separate them by commas so say I would like to print 4.5 and then I would like to print hello when you do this it will automatically add a space between the two things, let's just put another string here just to show you what I mean, so 4.5 hello, notice, add that space between now we'll talk about how you can print things. without the space in between later, but that's the basics of a print, if I want to print a lot of things on the same line, I can go to hello, I could say end, I can say 87, I can say false and I can run this and this all works hello and 87 false now there are some arguments that you can pass to the print function if you type a comma and then type end equals you can indicate what you want the end of this print statement to be by default the end here is a return of cart which is backslash n what that means is go to the next line after printing this line now notice if I don't add this backslash enter actually let me show you what happens by default so let's say I have hello and 87 I'm going to get rid of this and print both things, we get them on two separate lines, which is the default behavior of the print statement and it prints on a new line.
Now notice if I add end and end equal and instead of a backslash n let's say uh this pipe like this and I run this now at the end of the print statement, it just prints a pipe, it doesn't add the carriage return, which means it doesn't we move on to the next line, that's a little more advanced, but essentially the carriage return is that backslash n and again that means just moving on to the next line which is the basics of printing and output and now let's move on to the variables. Variables are an important part of any Python program.
They are quite easy to create when you create a variable in Python, you simply type a variable name, a space, an equal sign and then assign it to some value, this value will be some data type, some function, something else than we will talk. Later to give you a basic example I will set the variable hello equal to the value 10. Think of a variable as a bucket that stores some data or stores some type now if I want to access the value that is stored in hello what I can do is just say print hello, what this will do is say okay, this is a variable, I know it's a variable because I saw it earlier in the program, let me see what its value is and I'll print it. value so now I'm going to run and you can see we get tim let's make another variable let's call this world let's set this equal to the value world now let's print hello comma world and see what we get we get tim and then the space world variables They are somewhat complex, you can set them equal to other variables if I decide to change the value of world so that it is actually equal to the variable hello, what is going to happen?
It'll say, okay, hello, it's a variable, what's low? equals hello equals tim so I'm going to print tim now look what we're going to get we get tim tim now what happens if I come here and change hello so it's equal to no if I do this what's going to happen is the world won't change because world was set equal to the value of hello on this line at this point on line three because our program reads from top to bottom the value of hello was tim, so world is set to tim and then hello is set to no That doesn't change the value of the world, so what you'll see is we'll have Tim and then we won't, so let's take a look here and I'm sorry, the other way around, we don't have Tim, sorry. although first we print greeting and then world, I have that mixed up, i.e. the basics of variables, there are many other things we can do with them, but let me tell you about the naming conventions for them, so in a variable you are not allowed. have special characters and cannot start with a number so you are allowed to have an underscore which is the only exception in terms of special characters, you will usually use it when indicating a space and in Python the convention is usually to separate things that use an underscore in other languages ​​you might see something like hello world if you wanted to create a variable that has multiple words in it, but in Python they stick to the snake box which is what is known as the other is camelcase and they use underscores. to separate your variables just to give you an example of what I mean you can't start a variable with a number so 9 hello notice a red line appears here and I couldn't do something like hello 9 that doesn't work but yeah I want hello world 32, that's totally fine, it's a valid variable name, the next topic I want to talk about is how to get information from the user, just like printing something, it's very simple, getting information is also simple, what we do is simply using the input function we have our opening and closing parentheses and then we write what is known as a message inside these brackets like this now this must be in a string unlike the print statement we can't do something like 4.5 here that won't work.
I need a string, so what I'm going to do is add a message, let's say I want the user to type their name, then I'm going to say name, I'm going to make a colon and then I'm going to add a space between the colon and the end of the string, the The reason for this is that the user will start typing on this line right after the message, so if I don't have a space, what will happen is that the user will start typing right where the colon is, which of course won't. is going to be good, so let's go ahead and run this and take a look at what happens, we can say name colon, space and now I'm going to type tim, that's great, but how do we actually get the colon? value, how do we store what the user typed so we can use it later?
Well we need to assign this input to a variable so what I'm going to do is say the name is equal to the input, I just want to note that I forgot to say this earlier, we could capitalize our variable name if we want , that would be fine, but I'm not going to do that and now what will happen is that everything we write will be returned to us in this statement. as a string and it's going to be assigned to this variable name, so if I go ahead and print the name value, what's going to happen is whatever we type here is going to print out, so let's take a look at this name, let's type tim and see which tim is printed below, now of course we can get multiple user inputs, so I can say something like age equals input age, colon and now let's see what happens when I run this, so let's name to tim, age 20, and we could put print. those if we want, but I'm not actually going to do it, you know, let me show you an example where I print them out, let's say hello and then let's go to the comma name and then you have comma age years, so this is a way to we can combine variables and strings to print a responsemeaningful to say hello whatever name you have whatever your age years so in this case I'll say name tim age come on 12 and I say hello tim you're 12, okay that's all for the entry now let's move on and talk about how we can convert, for example, a numeric input into an integer or float because by default it comes back as a string, so the next topic I want to cover is arithmetic operators, these are essentially like plus minus exponent of multiplication how to perform math operations in Python is now something to keep in mind when we perform and use arithmetic operators, we have to make sure that the data types on the left and right The right side of these operators, also known as operands, are the same data.type or are both numbers.
What I mean by this is that if I have something like hello and I try to add 9 to it, that just doesn't make any sense and we will get an error and something will be wrong with our program. so keep that in mind I can't do hello minus 9. you can't do hello divided by 9. In fact, you can use multiplication. You can guess what that's going to do, but I'll show you later. Okay, so let's continue. the basic operators the first is the plus sign very simple we can add 9 plus 3 or in this case I could add x plus and then x is 9 and it is 3. we can add those two values ​​together ignore the squiggle when I save that Now something to have disappears Note if I do this 3.5, this works totally fine, although these are different data types since they are both numbers.
I can add them, of course, I can do the subtraction. Let's run, I can do the multiplication. it's an asterisk and I can do the division, we do the division and we get some crazy number, just keep in mind that the maximum precision in Python, I think, is 13 decimal points, there are ways to go beyond that, but that's too advanced . I'm not going to cover that here and when you ever do division or you're dealing with rounding and all that, it's always a problem on computers, so keep that in mind that you're not going to get the most accurate answers with division. so if this is a non-decimal point anyway, I hope that makes sense now I just want to point something out if I really have to say 9 over 3, of course you know that answer is 3 and that's a whole number, right, 3 is an integer, but this actually returns us a float that is not in int even though neither of these data types are float.
The reason for this is that every time we use the division operator it returns a float because it doesn't know if you're going to need to represent a floating point or you'll need to represent some level of precision, so keep that in mind if for some reason you don't want it. This is a floating point, of course, you can convert the result to an int just by doing int So, okay, those are some of the basic arithmetic operators. Next we have the exponent, so that's two asterisks like that. This will raise x to the power y, so we can see that gives us 729 and then we have floor division.
So what am I? What we're going to do here is convert this to 10. Guess what you think it's going to give us, but this gives us 3. The reason it gives us 3 is because this will give us the entire result of any division. Imagine this. it was like 9.333 or whatever it just removes all the decimal points and just gives or sorry, 3.333 removes all the decimal points and just gives us the following integer result is mod, this is the percentage sign that it returns us to, the remainder after a division, in this case 10 mod 3 is going to be fine, the answer is 9 and then the remainder 1 correct, so we get 1 of this here.
I think that's it for those operators. Now I'll just show you how. we can say the order of operations so if we want to order the operations we can use square brackets or if we want to evaluate things in a specific order this follows the simple order of operations whose acronym I know is bed mass which is b e d and hate this autocomplete, it makes it very difficult to do this but okay, so what this means is brackets exponents division multiplication addition subtraction Python follows the standard order of operations if you just write an expression, but of course it's always easier to use . parentheses and separate things so I can say something like x mod y and then I can multiply that by two since I didn't say it, integer division and mod operators are in the lowest order of operations so if you use mod that will be below addition and subtraction, I'm pretty sure it's correct, but can someone correct me in the comments if I'm wrong on that, but anyway you get the point, you can use square brackets and that's how you can perform and do arithmetic in In a way, the next thing I need to cover here is just an example using input, so what I'm going to say is num equals input and we'll just say the number colon like this and what I want to do is just print. the result of num minus five, so I want to take whatever number you type and I want to subtract five from it and print it on the screen, so let's try that. num is equal to five.
Notice that it says that the unsupported operand types for less are four, sorry, yes. minus string and int so what that means is that num is a string even though it looks like one inside us. I'll explain why in a second and we can't subtract the number 5 from it, that just doesn't make any sense, the program doesn't know what to do with that, so think about this, why is num a string that we write? 5. This should be an int value from what we understand about our data types. This input automatically returns us everything we write in a string. just imagine that anything we do here is going to give us a string and that means that if we want this to actually be a numeric value and we can perform arithmetic on it, we need to convert it to an int, so there's this fantasy. function called ins in Python this will take a string assuming there is an int inside that string and convert it to its integer representation.
Let's take a look now when I write a number, let's say 10, of course we get the value 5. it took num which was 10, so the string 10, you know, I will write it like here we have the string 10 and just converted it to the integer value real 10. Now you can imagine that we have other functions in Python that do this like well, we've said float that will take everything we have here and convert it to a float. Now notice what happens when I do this. If I float 10, we get 5.0. As long as you have at least one float in your arithmetic, it will return automatically. for you, a float needs to maintain the level of precision that was in the original operation that you know or the original value, so that's something to keep in mind whenever you're doing plus minus multiplication if there's a float like the. operand, so on the left or right side of the operator you will get a float result, that's all I wanted to show for this.
Now let's move on, so the next thing I want to cover is something called string methods. before we do that, I need to define what a method is, so let's create a variable, let's make this equal to hello and we can just say hello is equal to the string hello. I want to show you this function called type that will tell us the type of a variable, so if I print the type of hello, you can imagine what type it will be, it's just its data type, let's take a look here, we get a class string.
You can ignore the angle brackets in class if you are more advanced. you probably already know what this means, but essentially what it says is that this string or this variable here hello is an instance of the class string again, big words, you don't have to know what they mean, but for anyone more advanced, hopefully , that makes sense to you, so how do we use a method on a string and what is a method? Well, a method is simply something with a dot operator, so we have a dot, we have sum and name, whatever the name of the method is, in this case it's going to be top and then we have an opening and closing bracket or parentheses whatever you want to call them now I just want to show you what these methods do so if I say hello top dot this is a method that we can only call on strings so since this is a string I can use this top dot method on it and imagine what this is going to do, what it actually does is it capitalizes or puts the entire string completely in uppercase, so if I look now at hello and we print it we can see that we receive hello in uppercase now I don't need to call it like that I can also do hello period top now the reason this is going to give me the same thing is because well this is storing the value of the string which is hello and then I was just typing in uppercase here now what happens says okay well what is hello equals oh, well hello is equal to the string hello, so you can think of it as a substitution, this string just goes to where it is?
This puts it on top and then prints it. Let's go to the top. Now let's take a look at what bottom point you can probably already imagine, but it just makes the entire string lowercase. These are useful when you receive information from the user and want. to validate and check if it's equal to something we'll do later, so we have some other methods with capitalization of points. You can imagine what this does: it just capitalizes the first letter of the string and then capitalizes the rest to make it look nice. right, I had a sentence and I said hello world like this, let's take a look at this, it will give me hello world correctly and if I add a capital w like this, it removes it and just formats it as If a sentence were next, we have this method called count.
What counting does is count a specific string within the string to look for a substring in the string and how many times that occurs. Let's see. I wanted to see how many double l's there were. Within this chain, well, I can say hello. Count double l and then that will count and tell me how many are here. Now take a look and guess how many you think are here. Well, actually there are zero. The reason they are zero is. because these are uppercase letters and this was looking for lowercase letters, that's why it's very important to make sure you differentiate between uppercase and lowercase because two lowercase letters are not the same as two uppercase letters, but if you wanted to solve this problem, you could put the whole string in lowercase so I can say hello lowest point and then I could count all the double l's in the lowercase string, so now let's look at this, in this case we get the value one, let's improve this a little bit and search for all, are there any others we can search for?
I guess we can look up how many there are. Okay, in that case we get two or, so those are some basic string methods. There are a few more, but I just want to show you how you use them and the fact that you can chain them together because what happens is this will return a string. You can imagine that replacing this looks like, you know, hello world, and then it's going to count. all the o's inside hello world and they return us that value which in this case was 2. Okay, now let's move on to the conditions and conditional operators before mentioning that I just want to go over something that I forgot in one of the previous sections , this is simply string multiplication and addition.
This is important, so I'll cover it quickly, but essentially let's say I have a variable and that is equal to hello, so x is equal to a minimum, I have another one. variable and this is equal to, we can actually say 3. Well, there's something interesting in Python, but what I can actually do is multiply a string by an integer and that will just repeat the string the integer times, so if I say x multiplied by And although this is not the same data type that I said before, it could cause problems since it is a string and it is an integer and the string is on the left side, we can do this so we can say how this greets us because I multiplied the string by the integer, so something to keep in mind is that we can also add two strings together because that actually makes sense, so if I say hello and then I say yes, well I can add these two together, this is known as concatenation. let's take a look at this and it says hello to me and then yeah, so you can do that, you can add two strings and you can multiply a string by an integer, you just need to include that because obviously it's something that's important to understand all of.
Next we are going to talk about conditions and conditional operators, so a condition is simply something in Python that evaluates or compares two variables or data types and returns us a true or false value based on the comparison, just so you know, we give you an example of a comparison is x equals y is a boolean value, so let's see what these operators are. We have two equal signs that verify equality. The left side is the same as the right side. We have no equal, which verifies inequality. So the left side is not the same as the right side?
We have less than or equal to greater than or equal to less and greater than now there are some other random ones, we're not going to go over those, but these are the conditional operatorsmain and let me show you an example of condition, let's say I have x is equal to hello and y is equal to hello. I want to check the comparison, so I could do something like print x equals y, are these two things the same? Look, yes, they are, we get the true value, now let's do the not equal sign, aren't these things equal?
No they are not, so we get false, that is the basic concept of checking for equality. Now what happens if I add a capital l inside this string, well we know that lowercase and uppercase letters are different so if I do this we get true which means no these two strings are not the same they are different If I do the double equal sign then we get false. Now it's interesting that with strings we can actually compare them using the greater than sign and the less than sign which is now not very intuitive so I have to show some more primitive examples here to give you an illustration of how this works, but if I have something like a and I say is a greater than actually let's go with a capital z, what do you think the answer is?
Well, that's actually true, the reason for this is that each character within Python is represented by what is known as ascii code. We actually take a look at what this ascii code is by looking at what's called the ordinal value of a character, so if I print the ordinal of z, we can actually see that it's 90. If I print the ordinal of a, we can see that it's 97. So what that essentially tells us is that this uppercase z is actually represented by the number 90 and the uppercase o sorry. lowercase a is represented by 97. So what we do is compare the two ordinal values ​​of these characters and see that a is actually greater than z.
If we do this, I say a greater than b, then that's going to be false because b is actually represented by 98, there is a logical order to these characters, but I just want you to understand that we can compare strings using greater than less than equal to all them, but just understand that we are comparing the ordinal value. of the strings now let's say we have something like a b, what we're going to do is just go from left to right and compare all the characters, so we would say okay, it's greater than b, yeah, imagine these two are the ones same then we had a and then we had d so if these were the same then we would go ahead and compare the next character which would be b in this case we get false because obviously the d is greater this is how it works now let's just show some example numbers let's say 7.5 is equal to 7.
Is it true? Obviously, that is false. Let's say 7.5 is greater than 7. Obviously, that will be true. And what about 7.0 equals 7? Take a look at that. we get true, okay, that's the basics about conditional operators and conditions, of course, you can store these things in variables. I can say that the result is equal to 6, it is equal to 6. and we print the result like this and we get the true value, okay, let's move on now. to chained conditionals, so a chained conditional is essentially combining multiple conditions to create a larger condition. What I have here is a basic example.
I have three conditions. I have result one, result two and result three. Result one says that x is equal to result y. two says it's y greater than x and this one says it's z less than i do something like z minus two less than x plus two well that's not going to say z and then minus 2 less than that, it's going to evaluate to the left side and it's going to evaluate to the right side and then combine and use sorry. this conditional operator, I hope it makes sense, but keep in mind that you can actually write expressions on either side of a conditional operator.
Okay, now that we have that, essentially what I want to do is say: How can I make a condition that uses result 1, result 2, and result 3. So obviously, these are all equal to true false true false, they are equal to something like this, so what I can do is use three separate keywords, like this and or, oops, and no, like this, these three words. are what I can use to chain conditionals and create larger conditions from specific conditions, so what I can do is do something like this. I can say that result 4 is equal to result 1 or result 2.
Now, what does the left or operator do right? The hand side and the right side of o have to be a true or false value, which is why these evaluate to true or false. What it will do is it will look at the left side and the right side and it will say okay if the left side is true or the right side is true, all this condition is true, of course if both are false that is the only situation in which this whole condition here will be false, so in three scenarios, because here there are four possible scenarios, is will be true and the other scenario will be false, so if both are true, obviously at least one of them was true , so it evaluates to true, so let's print result 4 and take a look.
Now we become true. What we can do is add another one or if we want, we can say result 3. Now what this says is okay, if result 1, result 2 or result 3 is true, all of this is true, which, Of course, now it is. how can we combine other things into this, we can actually use this not keyword, what it does is it takes whatever is on the right side, so in this case it will be a true or false value and it just inverts it into this. In the case that result 2 is true, what is it, it will automatically become false, so if I can actually show you on a more basic level, if I just print a instead of result 4, I print that it is not true, so it will print the value. false which you can see down there and if I print not false then this will print true now what I can do is do something like this I can say not false or true so let's take a look at that and there we go we get false so take whatever be true and then you just reverse it and convert it with the no now those are two that we've talked about like this or and no now what about and like this and essentially says okay it's what's on the left side and what's on the right side is true if both are true they are true the entire sorry condition is true otherwise it is false so only in one scenario out of the four possible scenarios here with two variables or two values ​​on the left and right side?
Is this going to be true? So let's take a look at this and we get it as true because obviously this is false, then we nod and that becomes true now, of course, we can do a combination of and and or now when we use this combination of different things, so no, and we have to know which one is going to come before what kind of order of operations now, the way it actually goes is not first, second, last, so keep that in mind because that will be important depending on how you write your expression, like this that essentially, if I say false and true or true, what we're actually going to do is first evaluate the false and the true and then we'll evaluate the or of whatever it is. and then that, in this case this would be false, so we would get false or true and then this would become true, then we would have the no and that would make it false, so now we move on to the fun. things that in my opinion are the if statement if else if and else now this essentially allows us to check if something happens or if a condition is true and if that is true we can do something specific otherwise we may not do anything or that we do it. something different, so for the example I'm going to do here, I want someone to type his name and I want to say if his name is equal to, in this case, tim, I'll tell them that they're good at Python, I don't know. something random, so in this case, to do that, what I'm going to start doing is writing an if statement, so the syntax of an if statement is a condition like this, I know it's misspelled, but okay, condition, colon indented block, whatever you want to happen in the indented block and then that's the basic syntax of the if statement, so here, if I want to check if x is equal to tim, I'll say if x is equal to and then the string tim with a capital t i'll just print, you're great. so now what will happen is if and only if lucky so it will be. it's self explanatory so let's go ahead and do it tim we can see you're great always do this now let's do another name let's go with joe and it says always do this didn't print this statement now the addition to the if statement is of course I can add more things below this indented block so I make another print statement and that would add a space so let me show you how this works if I do that.
Now you'll see that we get that space by simply printing an empty print statement. Okay, now what we can do is say: Okay, how about I just want to print? You are great or I want to print some other message. I don't want to print two things. Well, what I can do is print. Can. add this one more, this one should come after an if statement and essentially what it allows me to do is say okay, if this is not true, do this, so it's an if else, right, if this is true, do this otherwise do this I'll never do both in this case I'll just print no you know it's not very intuitive or it doesn't really make much sense but that's okay so now I'm going to go ahead and say tim's name he says which you're great and actually let's stick with no and then it prints no okay so that's the basics about the if else now let's say we really want to check several things so maybe we want to check a bunch of different names and if the name is joe maybe we want to say you I know, thanks Joe, I don't know something random, well what we can do is use this elif statement.
The l if statement can be used as many times as we want, but it has to come after an if and it has to come before anything else, so we can't just go ahead and start writing these random elifs everywhere, they'll just come after an if statement, so there will only be one, if there is only one more, but as many elevations as we want and you'll see how this works in a second, so the syntax l is exactly the same except it starts with the, so I'm going to say l if x is equal to joe and I'm going to print for joe, why not?
Now let's run this, let me show you. What happens when I go with Joe? It says "Buy Joe and let's print something random. It gives us no now, of course, I don't need this else statement. I can use a life without the else statement. That's totally valid in this situation if I do it." something random just nothing will happen but if I put tim or joe then it will give me the valid answer now let's add another one if let's say lfx is equal to I don't know let's go with sarah we can print random okay and now let's try this and that works now of course we could add the else at the end but that's the basics for if l if and else now of course you can chain and add things inside another if statement.
You could put another if statement inside this one. but just make sure you keep the indentation right because that's how you determine what we're going to print and what we're going to do if this statement is true, so in the next few sections I'm going to talk about collections. how we handle collections that repeat over collections and all that fun stuff, but what is a collection? Well, a collection is simply a group of ordered or unordered elements. Now the two collections that I am going to discuss here in this section are lists and tuples, so if we have a list, a list looks like this, they are simply square brackets, now inside the square brackets we can have a series of elements, the elements are simply some type of data, so it could have the integer 4, it could have the value true, it could have some string high and these elements don't need to be of the same type like in many other languages, so this is a list and The way list works is that it can store a bunch of different items and a list is an ordered collection, which means the order in which we enter things into the collection is important and is maintained, in fact it is very important. in the list, so how do I actually access the list items?
How do I deal with the list? What are some of the things we can do with it? Of course, I can define a list by simply opening some square brackets and then defining some elements inside. I can also leave brackets like this empty, which would give me an empty list. The first thing I should look at in a list is this function called len. len will tell us the length of the list, this also works on strings and some other things, but if I look at the len of x it tells me 3. now just to show you here if I say y equals height y If I were to look at the length of and, after looking at the line of x, we obviously get 2.
So len is a function in Python that we can use to see the lengths ofthings, so that's one of the things that what we can do in a list, what we can also do is add things to it, what a pen does is add it to the end of the list, so if I want to add, say the element hello, can I say x point add now I can print. x and if we take a look we get four true highs. Hello, of course we add this item to the end of the list. I can also extend the list with another list, so let's say I have a list here and inside this list I have 4. 5 and just a bunch of other things, well when I extend it what it will do is take all the elements from this list and just add each one of them to the end of the list so you can imagine extending your internal implementation, you just loop through all of this and add all those elements to this list now, how about deleting something or taking something out of the list?
Well, I've already revealed what one of these things is, but what pop does is remove and return the last item in the list. So if I actually go ahead and print x dot pop, what this will do is it will print to height and it will remove the height from the list and you can see that when we print we remove from the end now another argument to pop is actually the index of what we want to remove when we look at a list, each element in the list is identified by a number, that number is known as its index aka its position in the list when we start looking at indexes in a list, we start counting from zero, so the first position in the list is 0, the next is 1 and the last is 2.
If we want to know the last index in a list, we search along along the list and we subtract 1. in this case we have 3 elements, the last index would be 2, the first is 0. So if I go ahead and say x dot pop 0, what that will do is remove the first element from the list which is 4. so now we remove that and all of a sudden, if we look at this new list, the first element at position 0, index 0, will be true. Now, if we simply want to access list items, maybe we don't want to delete them, we just want to see them. we can say something like x 0 equals and change its value to say hello now when I print means that this x here doesn't actually store a copy in the list, it stores what's known as a reference to the list and the actual elements themselves are stored somewhere else, so for people who are more advanced and they understand that.
I hope they came from another programming language that makes sense, but lists are mutable, meaning they can be changed. I can change all of these elements and if I do something like y equals x, I go ahead and make that change to x, but I don't get to y. You'll notice that x and y will be exactly the same, so I have hi true high, hi true high. When making a modification to x, I made a modification to y because x and y are storing a reference. to this list is not a copy of this list if I wanted to copy the list I would have to do this I would have to make two square brackets and a colon inside we will talk about how this works later but now notice if I made this copy that change does not apply to the other one list.
There are many other things you can do with lists, but those are the basics and I hope that makes sense. Next I'll talk about tuples, so tuples are similar to lists except that they are immutable. so a tuple uses square brackets instead of square brackets and works pretty much the same except we can't add, we can't delete and we can't change elements, so a tuple is really an immutable list, you can think of it like that, it means it can't be changed once it's been defined, if we want to change it, we actually have to redefine it, so what I can do is print, let's say x0 and okay, that will give me the correct answer, so it will give me zero, but if I go ahead and do something like x 0 equals 5 and I try to do that.
You will notice that we received an error because the tuple object does not support element assignment. The reason for this is because again it is immutable. I also can't do something like x. dot append, I can try it, but you will notice that again we will get another error. The tuple object has no added attribute, so this is a tuple, they are not used much, although they are used sometimes and just to note here, you can have lists within lists, so I can say something like, you know, you could have a tuple inside a list, you could have a list inside a list inside a list and you could have elements inside this, they don't need to be Sometimes the uniform size in other programming languages ​​when you're looking for an increase if you have embedded lists, each element has to be another list.
Things like that, I just wanted to point out that you can do something like that and I think that's it. Let's cover lists and tuples right now. Alright, the next topic I have for you is for loops. Now a for loop. If you've learned other programming languages, let us iterate a certain number of times, so we'll be talking. about a while loop the main difference between a while loop and a for loop is that a while loop runs an indefinite number of times we don't know where we are going based on a condition which we will see shortly a for loop we know how many times we're going to loop at least relatively so what I'm going to do is show you how we can create a basic for loop to print the numbers 1 to 10. 4i in range and then inside here we just put 10.
I'll talk about what does this range function in a second, but let me show you how the for loop actually works, so now I can show you that this prints 0 1 2. 3 4 5 6 7 8 9 does not include 10. So the way we set up a basic for loop if we're just going to iterate through the count is we say for i or for some variable this is going to be our iterator or a counter variable, whatever you want to call it, this is a keyword that we always have for i and then some word here , in this case we are going to put range range is a function that actually creates a collection of numbers based on the input that we give it for range is the next start and stop step, so we can put up to three um and we can have less than three arguments within this range function, essentially the start and stop step says, okay? we want to start at what number do we stop at, what number do we step at now if we only have one argument so we just pass one number by default which is the stop argument we usually start at zero so by default By default our range will start at zero and we'll go to whatever number we put in here most of the time you'll just put in one number and this defines the final range so in this case it says okay we'll start at 0 and continue to go up to 10 but not include 10.
Notice that we don't print 10. Now if we had two arguments, that's going to be the default start and stop, so we'll say okay, we'll start here at 1 and stop at 10. but we don't include 10. If we add 3 we will include a step and that tells us how much we should increase each time. By default, we increment by 1, but we can increment by 2 and we can also increment by a negative number. we actually say we want to start at 10 and we want to get to negative 1 and we want to go to negative 1. Well, let's take a look at what this looks like and let's try it out, okay, so running you'll see that we start at 10 right there and then we go down to zero and of course we were able to start at minus 10 and see what's going to happen here, we don't nothing, the reason is that we started at minus 10, we were going to minus 1 and we are passing through the negative 1, but since we already passed the negative 1, obviously we are not going to go there and we stop immediately, this is how the range function works , so for i within range again start the stop step by default if you just put one argument which will be the stop, if you put two which are start and stop you can play with that and see how it works but I think which is a sufficient explanation.
The next thing we can do is loop through a list. let's say we have 4i in and now instead of range we will just put a list, we will say 4i in range and we can do 3 4 and just a bunch of numbers here now if we print i it will just print all the numbers in that collection or in that list they will be checked one at a time and they will print them all. Now let's say maybe we didn't want to do that, maybe we actually wanted to keep track of what index we were on and we could. let's say x is equal to the list, we would say 4i in x and then, sorry, that wouldn't actually be the right way to do it, we could say 4i in the length range of x and then instead of just printing i, we could print x in brackets.
Let's take a look at this here, you'll see how it works, the way it works is we're going to go up, but not including the last index of x or the length of x, sorry, in this case 1 2 3 4 5 6 So this here it will say 6. So for i in range 6, that means the maximum value of i will be 5. So we say x 0 x 1 x 2 3 4 5 and print all the values ​​that are there now. Another fancy thing we can do if we want to avoid usage is called listing. What enumerate will do is create indexes and values ​​for all the elements in our list, so we would say comma element 4i in enumerate x and then what I can. what we do is a comma element and you will see how it works.
What we do is we get 0 1 2 3 4 5 and then all the elements, so this works as a combination of the two for loop styles. I just showed you where. we actually have a range, so we go from zero to five, that's all the indexes in the list and then we print all the elements for each of those indexes in the list and we just have two variables here that denote it, so the next The topic to discuss is while loops now, while loops are pretty simple, essentially what they are is while condition equals true, go ahead and do something, so we'll have some condition here before these colons and then after the colon, there will be an indented block and whatever is in that indented block will be executed inside the loop as long as that condition is true to illustrate this I will say it is equal to zero, let's say as long as it is less than 10 we will say execution printout and then we'll say i plus equals one, this is another way you can add two variables, so you could say i plus equals one or you can do i plus equals one.
You can also do something like i multiplied by 1 or divided by 1. so multiplied by equals 2 what that's going to do is say, okay, multiply i by 2. We could do something like that if we wanted and also show you more syntax for some things interesting things we can do in Python, but that's the basics of a while loop if I go ahead and run this, we can see that it will run 10 times and there's really not much else to talk about at the moment other than the fact that we can implement a break statement so we can also write the same thing. code like this while true i plus equals 1 and then if i equals 10 break and that will just exit whatever the loop is closest to us imagine if we had another while loop like this and we said while true inside here, so this would be break this while loop, not the other while loop, hopefully that makes sense anyway, let's move on to the cut operator, so the cut operator is personally my favorite part of Python.
There are implementations in other languages, but none of them are as good as Python in my opinion. and what this essentially allows us to do is take a chunk of a collection like a string or a list or a tuple and do something with it, so let me show you what I mean, the chunk operator is just square brackets like this with a sequence of two points and numbers inside it, the way it works is that we have a start, a stop and a step, like the range function we saw before, so if I put something like x here and then start, stop, step, what I do.
What I can do is say, "Okay, I want to start at zero, I want to stop at the index." These are all the indexes that we are putting here three and I want to go to two. Now, actually, let me stop at index 4 so we get something. There are more values ​​here, but let me show you what it looks like. We get the value 0 2 when I have 0 4 2 in my segment. What this says again is start at the first index, which is 0, go to the fourth index, but don't include it, which means stop as soon as we get to this and go to two, so we'll start at zero, then go to two and then we will go to four, but since four is the stop, here we are.
We're not going to include that in our segment now, when we do the segment operator, we don't have to include all these different things as arguments, in fact, what we can do is just include a stop, just include a start and all that. like the range function if we don't include anything so sorry we only include twopoints like that and then we put something on the right side that says stop at whatever index we put here, so if we do this it says start at the beginning and stop at the end now if we do something like 2 colon it says start at 2 and stop at end, so every time we leave a blank space we assume it is the end or the beginning or one in the case of a step, so if I did two two points two points maybe I did two two points four two points this says okay start in two stop at four and then go to one but I don't even need to include that I could do two two points 4 but now let's say I wanted to go to 4 and then two points two points negative 1 what this says is okay start at 4 go to 2 and go to minus 1.
So now what this is going to do is start at 4 which is actually this and it's going to give us 4 and then three and then it won't include two or any of the others, so that's what we'll get , in fact, let's look at this, we see that we get four, three, now one of my favorite things with a slice operator. is reversing a list, all we have to do is two points two points minus one, this means start from the beginning, stop at the end and then I go to minus one, so this will actually start going backwards, which is kind of interesting , so when we look at that, we get eight seven six five four three two one zero which is an easy way to reverse a list in Python now, of course, all of this also works on a string, let me show you that with s, as you see, we can reverse the string that way and We can also use the standard arguments that we would normally use.
Maybe we go step by step in two, so let's start from the beginning, stop at the end and step by step in two, we get hlo, so that's the basics of the cut operator. There are a few more things. What can we do with this, but this is how it works and I think this also works in tuples. We can test it to make sure I'm not lying to you, but if I do, you'll be able to see it. that actually works and we can use slice on any type of collection of elements, so now we move on to sets which are an underrated but extremely useful data type in Python.
Now a set is simply a single unordered collection of elements. that means no duplicate items, we don't keep track of the order or frequency of items, the only thing we care about is whether something is there or not, the reason we do this is because a set is extremely

fast

to make what are called searches deletions or additions when we talk about a list, let's say we have something that you know has a lot of elements, if we mean removing the first element from the list that actually involves changing the position of all the others. elementsBecause we are keeping track of the positions of these elements with the set, since there is no notion of position, adding and removing something is as simple as just adding or removing that element, no other operations need to be performed, which means which is very fast. use, so think of a set that will be used only in a situation where you care about whether something exists or doesn't exist, not about the frequency or order in which that item exists, so creating a set is pretty straightforward, we can say x equals set and we use the opening bracket and the closing bracket now, the reason we don't actually write something like say What this will do is create a dictionary now technically if we want to create a set we can do something like this and this will create a set for us that initially has the elements 4 32 and 2 inside it.
This is what is known as a literal set if you are not creating an empty set. It's totally fine to do it like this as long as you add an element inside, but if you're creating an empty set then you need to use this constructor; otherwise you'll end up creating a dictionary that's not what you want to test. A simple point for you: I'll print the representation type of an empty set, you know, and you'll see that it gives me a dict like this, of course, that's not what we want anyway, let's take a look at this set and just Le I show what I mean by unordered single collection of elements so 4322 if we print that we get 32 ​​to 4 so it's obviously a different order than what we added there and notice that the two duplicates were removed now the set operations are quite simple. we can add something to a set with s dot add our set dot add I'll put five and inside here and let's keep printing there we go we can see we added there we can also do s dot delete 5 and that Okay, since there's nothing there, it's going to give us a key error now if there is an element there, we can do it like this, it will delete that element for us and then there are some other things we can do as well for a set. one of the good ones is to check if something is in a set.
What I can do is say 4 in s. What this will do is simply check if element 4 is in the set and give me a true or false, in this case it is true and remember this happens in what is known as constant time which means it is extremely fast to do this instead of a list, so we could say 33 in s, that will give me false. Now the parallel I want to make here is if I had s is equal to 4 32 2 2 like that, so actually let's go to s2 and I said print and let's go to 2 in s2.
This operation, the one that is actually in the set, will happen much, much, much faster than this, of course, this one. It's not a big deal right now because these collections are quite small, but as they get extremely large, understand that using a set is very beneficial when it comes to searching for things, checking if something is there, deleting and deleting, there are some other operations that we can perform. what we can do in sets, let me define s2 and I'll quickly show you some of them. We can do, for example, the intersection or union of these sets, so I can say s dot union s2 and we'll go ahead and have We take a look here and we can see that we get the union of these two sets, essentially adding them together, we can make the difference of the two sets if we want, we can make the intersection and we can make the difference symmetric and all those other fun things you can do with sets now.
I'm not going to go into all that stuff just know that these are sets and those are some of the things you can do with them so now I'm going to talk about dictionaries if you're from another language what you may be familiar with here is a hash table or a map, something like that, are very similar to dictionaries, but a dictionary is essentially a key-value pair, it has some key, it has a colon, and then it has some value. Which applies now, of course, that value has to actually be a valid data type, but it could be something like a list, it could be a single value like that and the way you access it and create new key-value pairs is something like this.
I can print, let's say keys and you have values ​​now to add a new key is pretty straight forward what you can do is say x inside the square brackets you can define any key you want it can already exist if you want we can say something like key2 and we can set it equal to 5 .now note that these keys don't need to be the same, sorry, same data type, so I don't have to have two string keys. I can have entire keys. I can have whatever keys I want. Do something like x2 equals 8 and there we are.
See, that works perfectly fine, in fact, I can make this a list just to show you that the values ​​don't have to be the same either and voila, as a set, this actually works using a hash, which means this. It's very fast at retrieving added and modified values ​​within the dictionary, in fact it's so fast that you can assume it's constant time, although there's a chance that there are something known as hash collisions, although I'm not going to talk about that. because that's probably a little bit more advanced than most of you know, anyway, what we can do here in terms of operations on dictionaries, we can check if there's something in the dictionary, so I can say okay , there is some key in the dictionary, key in x.
There we are going to print that and it says true. Some other useful things we can do is get all the values ​​from the dictionary so we can say x point values, print that and it says addicted values ​​and gives us a list. of four, usually when you do this, you'll want to create a list out of this because it's a different data type that comes back to us and voila, we get the value 4. Now similarly we can do dick.keys. so x dot keys and there we go, we get a list that has all the keys in terms of iteration or elimination of values.
First I'll show you how to delete something to delete something, we can say x and then the key we want. to delete in this case, this key will be deleted, so let's go ahead and do that, and well, I guess it didn't actually show you that it was deleted, let's just print it to show that there you have it and we get an empty dictionary of Of course, as I showed you before, we can use it in the operator and loop through it. There are actually some interesting ways we can do this, so I can say a key value in x point elements and then what this will do is just return to Give me all keys and values ​​so I can print the key value and you'll see we'll get key four, so if I want to loop through all the keys and all the values, I can use dot elements if I don't want to.
Do that, I can only say four keys and then I can say in x. What this will do is just give me all the keys in x and if I want to access the value, of course, I could say key x like this and it will give me that. It gives me the value and the same thing appears, which is kind of like the basics for dictionaries. There are also some other methods, but I'm not going to talk about those. That's a dictionary and the next one is fun. As far as I know this is understanding, Python is one of the only programming languages ​​that actually has this, a lot of people hate it but I personally love it and if you learn to love it you can use it pretty well now to make an understanding, essentially what it is is a one line initialization of a list of a tuple of a dictionary of many other things, so let me show you what I mean, I can do something like x equals a list and then I can say x for x in rank five now, if I go ahead and print out the value of x, you'll see what we get here.
Let's run it like this, we get zero one, two, three, four. The way this works is essentially, we can define a for loop inside. of this list and what it's going to do is say okay, we're going to loop through it like we do normally and whatever we have here on the left side is actually the item that we're going to add to the list so we can do something like x else 5 for x in range five and there we go we get five six seven eight nine ten I can also do something like x mod two or x mod five there we go, I can also, you know, take something else I could say zero for x in range five, that would give me a list of all the zeros.
You can see how this could be useful now. If we want to get into a more complex example, you could make a list and then within this list you could. let's say 0 for x in range 100 for x in range five now what that will give us is five of these lists, each with one hundred zeros in it. You can see it's pretty big, but that's how it works now. Also go ahead and add some more complex stuff to this and let's say 0 for or I can say i for i in the range 100 if i mod 5 equals 0.
So essentially, if i is divisible by five, then what we can do en Actually, add it to the list, let's take a look at that and there we go, we get all the increments of five so you can play with that and see how it works, but this also works for dictionaries, in fact, let's do the same thing here. let's make it a dictionary and now we'll go with colon zero to have all these keys that are initialized to zero, we go in there and take a look, we can see that the dictionary works and of course we could do the same for a set we can just say i by i in the range blah blah, and there we go, now we get a set, so we can do this for tuples as well, except we won't do it the way you might assume if we just go ahead and do this, this will actually give us returns what is known as a generator object.
It's a little more advanced for this type of video, so I'm not going to talk about that, but what we can do if we want this to work for tuple. If we actually write tuple, we can use the tuple constructor, which is just this, and then do the comprehension inside of there now that will return the tuple to us. You can see I tried doing it another way before and that gave me the generator back. object anyway, that's understanding, these can be used in many different things, they are definitely interesting and good to know and one of the best features of Python that is not in many other languages, so now I'm going to start talking aboutfunctions. so to define a function in Python you simply use the keyword def, this means define, then you choose the name of your function, in this case I'm going to choose func.
Function names are the same as variable names in terms of how you name them. put some positional parameters inside here if you want or you can leave it empty, add a colon indented block and then everything inside the indentation will be executed when you run the function, so let's go ahead and run this and show you the basics of This is pretty much how you run and define a function, of course you can define multiple functions, you can actually define functions within functions if you want, this is totally valid if you wanted to do something like this and then you could call funk. so now of course this is a more advanced use case, but I'm just showing that you can do it because of the way Python works; in fact, functions are actually objects, which means you can technically return them.
I'll show it in a second, but come on. First I'm talking about arguments so let's say I want to add the argument x and inside here of course that means now when I call the function I need to add some value for x and for y so let's go five six and now if I run I want to print them, I can print x and I can print y, let's take a quick look, we run 5 6. Of course, we can also return something from a function, maybe I'll return x multiplied by y now if we actually go ahead. and print the value of this function, what will happen is it will evaluate what is here, return it to us and print it, we get the value 30.
Now note that when you return various things from a function that you can do, I can return x multiplied by y and maybe x divided by y as well, this will return us the value in a tuple, so if you look here we get actually two values, I guess we have the value x and here and that's inside a tuple now if we want to unpack this tuple and say separate it into different variables. Of course, we could index at zero and index at one, but a much cleaner and faster way to do it is to do something like r1 comma r2 equals func 5 6.
What is this going to do? What I do is take these two values ​​here and just separate them into the variables r1 and r2. Now, if I go ahead and print r1, r2 and look here, you can see that we get 30 and then 0.83334, which is the basis of a function. if you want to make a parameter optional you can do something like z equals you can set a default value. I usually set it to none and what this means is that you don't have to pass it, but if you want, you can. will override the optional value you have here, so let's start by printing zed.
I'm not going to zed him to begin with. You can see that, wow, let's run that for a second. We will execute five six none and now yes. I add a z, so let's add seven. There we see that instead of none, we will get seven printed there, which are the basics of a function and now we will move on to other more advanced aspects of all of this. Okay, so I'm going to talk about something that's really cool called the unpack operator and then I'm going to talk about star args and star star quarks, but first I want to show you an advanced example of a function, so if I say define func like this and then maybe I'll say take x and define function 2 inside here.
This is totally valid because of the way you can put a function inside another function and then inside here what I'm actually going to do is say this function is going to print x and I'm going to return function 2, but notice that I don't call it now, this is just to show you that functions are objects therefore they can be passed as variables so what can I do? What I do here is I can go ahead and I can say print or sorry, don't print, but I can call function 4 or function 3 and then I can call it like this.
What this essentially does is say, "Okay, I'm going to call this function." here with the value 3. what this function does is return another function to me, so it gives me function 2. notice that it's not calling the function, it's just returning it now, actually I'll just show you what I mean first before confusing someone. Print this before doing the calling statement, but you can see that this is actually telling me that it is a function object, it is a function 2 of func.local. So it's pretty much saying that funct2 is defined inside func now if I actually call this. because that's just the function or object reference, it's not actually what's being evaluated, if I call it that, we can go ahead and we get 3 and then we get none, of course the print statement won't print any because it doesn't there is nothing. to print from func return 2 but just take a look here we get 3. now this is equivalent if I did something like this I said you know x is equal to func and then on the next line I just called x since x is equal to a function function two, I can call it just like I showed you before and there we go, we get three anyway, that's the advanced aspect that I wanted to show now what I want to do is show you about star args and star star quarks uh, so I'm going to put it like so, so before we define what it does, what I'm going to do is just show you what the unpack operator is in Python, so let's say I have a list, maybe let's call it x and I just have a bunch of random numbers in this list , so what the unpack operator does is actually separate all the elements of a list or collection into individual elements.
The best example of this is the print statement if I print an asterisk that instead of simply printing, know how to say the complete list, what you will really see is printing one. point two three point two three six blah blah, you get the point, that's what this is going to do, so just look what happens when I print, I get all these things separated by spaces, like what happens if I just pass them . individually I'm not in the list, now look what happens when I just print x, let's take a look, it actually prints the list, so what it does is it unpacks everything we have into a tuple or a list or some kind of collection and sends it. through as arguments to a function, that's where the star arguments and the star quarks come in, although you'll see that in a second, so let's say you know x and what we need inside a function, we need to pass x and what will this do. it's just print for and say four pairs in pairs and what I want to do is call this function with those pairs.
Now the naive way to do this would be to go to func OK par and then par 1. Great, that would work, but it doesn't. the pythonic way to do this what we can actually do is make a couple of asterix and what this will do is take 1 2 and take 3 4 unpack them, separate them and pass them as arguments to funk, so if you take a look at that, that it really works. and that's why the unpack operator is really useful. You can also use it in dictionaries and I'll show you how it works with dictionaries. A little more complicated.
Includes two asterisks. What this does is if I have keys, I can let's say x represents obviously the argument , needed two asterisks because This was a dictionary and that's how it works. Yes, I don't think I need the for loop anymore to illustrate this, but the double asterisk is used for dictionaries. The single asterisk is used for a tuple or a list. Now I just want to make it clear that let's say these are not in the right order, so it's y and then x, this will still work and that's why it's really useful because you don't have to have it in the right order.
As long as you name the arguments as keys, hopefully that explains to us how star arguments and star quarks work, so star arguments and star quarks essentially imagine that you have a function that doesn't know how many positional arguments or keyword arguments . you want to accept that that's what quark means keyword arguments, well what you can do is use star args and star star quarks and what that will do is allow you to pass an unlimited number of regular arguments and keyword arguments, so if you really go ahead and go funk and then I pass like one two three four five and maybe pass some keyword arguments like you know one equals zero two equals 1.
I know this doesn't really make any sense, but you get the point. idea. If I actually run this and print it, you can see that when I print arguments and print quarks we get a tuple that has all the positional arguments which are these and all the keyword arguments which are 1 and two now if I actually wanted to use any of these , what I can do is uncompress them, so first of all I can uncompress arguments and what this does if we take a look here is it will print one, two, three, four five. You could try unpacking quarks. but you'll see what happens when you do this and hopefully, if you remember the last example, you'll realize why this isn't going to work.
It says 1 is an invalid keyword argument to print, so what will this do when I decompress quarks, it will take all my keyword arguments and say 1 equals 0 and say 2 equals 1 and pass it to the statement printed. Now, obviously, 1 and 2, well, those are not valid arguments for the printed statement. So anyway, we'll get an error that it's args and quarks. You'll have to research this on your own and learn how it works, but that's the basics and I just wanted to show it off. so you know you can do these cool fancy things in Python, the next one will be very quick, but this just defines the scope and the global, so when we look at a function like this, there is the notion of scope, so we have x is equals tim, we have defined func and then we have name as a parameter and what we are doing is saying okay, we are going to change x to be equal to name, so essentially if I were naive and didn't know any better, I would assume that What will happen is that this variable up here will change when you pass this name to this function.
Any of you who have programmed before probably know it's not going to work, but take a look. here you can see that x does not change before or after when I call func with the changed string, the reason is that this variable x is local and within the scope of this function, which means it cannot be used to access change from with from outside the same here with this x, this is actually global, this is in, you know, it's not defined within any scope other than this file, which means that well, I can't change it directly from this function , however, you could access it from this function.
I could print it here, but I can't actually change its value because if I do that, what's going to happen is I'm going to create a new x inside of here that's equal to the name and it's going to be local to this function. won't modify this, however there is one interesting thing we can do in Python, which is the global if i global x keyword. Now you'll notice that the expected behavior will occur now that we get tim and change what that says. Well I want to use can use and I feel obligated to show you because there are some very, very rare situations where you might need to use it, so now I'm going to spend about 10 seconds showing you how to raise an exception in Python, there's a keyword. called raise maybe in Java you've seen something like throw and raise can throw an exception if you wanted to do that so I could throw an exception and then inside of here I could just say wrong you know what I want now if I run the program so soon as we get to that line I will immediately get an exception and it says exception raised bad exception bad of course, that's the basics, there are more arguments and things you can do with this.
This is a base class, which means you can extend it when you get to object-oriented programming, make your own exceptions and do all that fancy stuff for our cases, that's all we really need to know. You could raise an error like a file exists, any other type of error you want, and then add again. some description by simply putting a string inside the square brackets, but that's enough. Now let's show how we can handle exceptions. Now that we know how to throw exceptions, it makes sense to learn how to handle them in Python. instead of having a try catch, we actually have a try except finally block, so what I can do is something like try, that means I'm going to try to run whatever code is inside of here, maybeget an integer. division by zero error so I can tell if 7 over 0 will throw an error then I can create an exception block I can accept an exception as what this will do is mean that any exception will be stored in the variable e and then I could print that exception and we can continue running the program.
This is the basic intent, except the block. Actually, there is no need to define anything here. I can only say try to accept like this if I want and also accept a specific exception, so I don't have to just throw an exception, this is general, this means that any exception that occurs, I will actually catch it. You can only catch specific exceptions if you want, but again, that's up to you, so in this case you'll see that we get division by zero, it's just printing, but it didn't actually show up or, you know, it shows us that error, like this that generated it, but we didn't really see it now.
If I go ahead and do this, what we can do is say oh. Well, that's the real problem and now our program is going to crash and it won't work, but if we have this block except this one, of course, we're done. Now there is also the notion of a finally block, the final block will not be executed. No matter what you normally put cleanup type operations inside here, maybe you're trying to write to a file, some exception is thrown and then, regardless of whether this was successful or not, you want to close the file after putting it inside finally , so I could say print finally like this, take a look here and you'll see we're finally there.
I'm not going to go over this too much. I guess if you're going to use this, you'll understand how to try to accept and ultimately work, but that. is the implementation in Python and that's the basics of raising and detecting an error and now we're going to discuss lambdas, so lambdas are actually a really interesting aspect of Python. I'm pretty sure they have them in many other programming languages ​​like well, but it looks like this, essentially a lambda is a one line anonymous function, which means it's not really a named function, you don't define a lambda using the def keyword, what you can do is something like x is equal to lambda x and then x plus five what this means is that this lambda will take an argument which is x and return x plus 5 not multiplied by x.
I want to do that? That means if I call x like that and go, I don't do it. I don't know x2 and we print this out, let's go ahead and take a look at this here. Oops, again, I didn't mean to do it, we see that we get the value 7. Now I will point out that this is not the recommended way to use a lambda. We'll look at how to use it in just a second in the next section, but this is the basics of how it works. It's just a one line anonymous function, so I can also do something like x and and then I can do something. like x plus y not uppercase y and if I go ahead and call x with I don't know 2 3 or 232 sure that's fine, let's take a look here we get the value 34.
So I hope that makes sense in how the lambda works. It seems intimidating but it's actually not that complicated and in the next you will see why they are useful and now I will tell you about the map and the filter, which are two useful functions in Python that now make use of lambda functions. You don't necessarily need to use the lambda function, but it is often useful, so let me show you what I mean. Let's make a list. Let's add Oops. I wanted to make a few more commas. Let's add a bunch of elements. inside here to make it a little nice and long so we get some interesting results and now what I'm going to do is just show you how we use the map, so what the map will do is take all of the elements in a list and use a function to assign them to a new list, so if I say something like mp which means map, I can say map which is the actual function.
Now what I do is put a function inside here. which I want to use for the map, so this will make sense in a second, but I'm going to say lambda x x plus 2. Basically, this means adding 2 to each of these elements or adding 2 to x in this case. and then what I do is I just pass in x. Now I know that so in this list x to this lambda function, which means take this lambda function and apply it on each element of x. and then put that in a new list. Now what I'm going to do is print the list representation of mp map.
It actually returns us a map object that we can use if we're going to iterate over it, but it's usually more useful to just convert it directly to a list, so let's take a look at what this does and voila, now we get three four six and you can see that all of these elements have been added two at a time. Now we can do a more complicated operation. one, maybe we can multiply it by two, you'll see a bigger difference and there we go. The next function I want to show you is filter, so I hope you have an idea of ​​how the map works, but filter, I don't want to say it. the opposite, but it does something a little bit different, so this function here, which is lambda, what it's going to do is instead of returning some value, it's going to return true or false and tell us whether or not to include the element. in our final filtered list or filtered object, essentially this lambda function or whatever function we put inside here has to return true or false based on the value of an element, so what you could do is say something like i is i mod 2 es equals 0.
So this means that you will only return it if it is even. This is the function that takes some value. It tells us if it's equal to or, sorry, divisible by 0, and if it is, we'll include it, so let's take a look now. We can see that now we just get all the even elements in our list, of course what we can also do is define a more complicated function, so we can say define func takes some value, let's go with i and we can do the same thing here. I could say that return i mod 2 is equal to 0, but we could also say that you know that i is equal to i multiplied by 3, so we can do that and then we can say that i mod 2 is equal to 0. so instead of use a lambda here we could just just type func that's totally fine so we just put the name of the function we want to use and then we run this and it works fine but that's why lambda is useful because a lot of times you don't want to define your own function. up here you just want to define it right inside the map declaration or the filter declaration, so that's where you would use this.
There are a few other use cases for it, but this is the most common and where you will see it often. Anyway, that's map and filter and for our last and final topic, I'm going to cover something called f-strings. Now f strings are new in Python 3.6, if you have a version earlier than that you won't be able to use it. f strings but they are a really cool way to manipulate and create strings so what I can do is do something like x equals I can do a lowercase f or a capital f it doesn't matter and then a string notice this will highlight o maybe it will be the size of a towel depending on what editor you're using and well, what you can do is write a string like you normally would, except now if you want to embed an expression, what you can do is do that. inside the braces so I can say hello and then I could say like you know six plus eight and this will actually be evaluated and now when I print this it's going to give me the answer 14.
So this is great because if you have some variables say like if you know, I don't know that tim is equal to 89 or something and I want to embed it in the string without having to concatenate it and convert it to a string with str. I can just use the f chain and embed with all the formatting, uh, putting it inside these curly braid straps, that's how it works. You can go ahead and play with this if you really want to see how it works, but essentially you just put an expression inside these curly braces and they will be evaluated and then converted to a string.
A very easy way to work with strings, of course you can also print a string f. I could print hello and then we can do that and actually let's run this and just look at what we get and there we go, we see we have hello 89, so those are f strings, with that being said, I'm going to conclude the video here. I'm officially out of breath. I went through this tutorial very quickly for the purpose. Do it as quickly as possible and not waste your time. If you appreciate this effort, please leave a like, subscribe to the channel, and of course let me know what you want to see next.
I'll quickly mention that I missed a few things in this video specifically object-oriented programming and advanced language features. If you want to know about those two things, I have a ton of resources related to them, I'll leave them in the description. The first is a video about objects that is about an hour long. oriented programming in Python that covers all the fundamentals and everything you need to know. The following is a complete series on expert level features in Python. I think it's about six videos and it covers things like metaclasses, context managers, generators, all that stuff anyway.
I said I hope you like it leave a like subscribe I'll see you next time

If you have any copyright issue, please Contact