Blog.

Backend Python Part 1

Cover Image for Backend Python Part 1
Bryan Guner
Bryan Guner
No date

Here is a full list of what is covered in this course:

  • Introduction To Python
  • Installation Of Python
  • Hello World In Python
  • Variables In Python
  • Strings In Python
  • Numbers In Python
  • Getting A User's Input
  • Word Replacement Exercise
  • List In Python
  • List Methods
  • Tuples In Python
  • Functions In Python
  • The Return Keyword
  • IF Statements In Python
  • Building An Even Number Checker Program
  • Dictionaries In Python
  • While Loops In Python
  • For Loops In Python
  • 2D Lists
  • Comments In Python
  • Building A Basic Calculator
  • Try Except In Python
  • Reading Files
  • Writing Files
  • Classes and Objects In Python
  • Inheritance In Python
  • The Python Shell
  • Building A Simple Login and SignUp System
  • Modules and PIP In Python
  • Introduction To Django
  • Installation Of Django
  • Url Routing And Django Apps
  • Django Template Language
  • Sending Data To Template File
  • Building A Word Counter In Django
  • Get vs Post In Django
  • Static Files In Django
  • Introduction To Django Models
  • Django Admin Panel & Manipulation Of Database
  • User Registration In Django
  • User Login And Logout In Django
  • Dynamic Url Routing In Django
  • Postgresql Setup
  • Building A Blog With Django - Part 1
  • Building A Blog With Django - Part 2
  • Building A Weather App With Django - Part 1
  • Building A Weather App With Django - Part 2
  • Building A Realtime Chat Application With Django - Part 1
  • Building A Realtime Chat Application With Django - Part 2
  • Django Rest Framework Crash Course

Watch the full course below or on the freeCodeCamp.org YouTube channel (10-hour watch).

Transcript

(autogenerated)

This comprehensive course is for absolute beginners, and will teach you back end web development with Python.

You will learn the basics of Python and Django and create a few projects along the way.

Tommy has created many popular courses, both on his own channel and on the Free Code Camp channel.

Hey guys, welcome to this back end web development course with Python.

In this course, we're going to be learning everything you need to know to start your web development journey with Python.

Let's take a quick look at the agenda of this video.

First, we will start from learning Python, which is a programming language we're going to use in this video.

In the Python tutorial, there'll be lots of exercises in which we're going to do together just to get comfortable with the Python programming language.

Once we are familiar with Python, we will move straight into Django.

Now Django is a Python framework, which is used for building server side web applications.

In the Django tutorial, we will learn all the concepts you need to know while getting started into January.

After that, we're gonna build three different projects using Django.

The project we're gonna do a blog application, a weather detector program, and a real time chat application using Django.

We're gonna build out this project so you get familiar with building your own project in jungle.

After that, you are going to get introduced into API's with Django, you will learn how you can view the rest API's in Django using the Django rest framework.

And I hope that after this video, you'll be comfortable with building your server side web applications using Django.

Now, I have some free resources like a Django roadmap Python data structure cheat sheet, a Django cheat sheets are plenty more free resources in which are compiled into a PDF.

And you can download a PDF for free using the link in the description below.

And if you like more tutorials like this, you can also check out my own channel at COVID told me where I teach more Python and web development in general.

Now have you noticed that let's dive straight into this video.

This tutorial is a bite of food because we are going to be learning python programming from scratch.

So this is a list of everything we're going to be talking about in this video.

So let me give a brief introduction to Python.

So Python is one of the fastest growing programming languages in the world.

with Python, you can go into various fields like machine learning and AI, web development, and plenty others.

So take into lambda scores and easy to learn Python with a very good decision for your programming journey.

So without wasting any time, let's get straight into the tutorial.

Right here, I'm just on my browser.

So we're gonna download Python on our laptop.

So to do this, I'm just gonna search for download Python for Windows since I'm on a Windows, and I'm going to click on the first link.

And then right here, I see download Python 3.9 point one, which is the latest version.

So we're just going to click on it.

And then you can see that it downloaded it automatically.

So I already have Python downloaded.

Now what I just need to do is to install it, I'm just gonna come into where I saved it.

And then I'm going to run it.

So make sure that when you're installing Python, you must stick this out Python to path.

If not, you're just going to make it more complex.

And it's supposed to be for you.

So let's click install now.

Yes.

And so this is just going to install Python on our machine.

It should take a few minutes, a couple of minutes to install.

And I'm going to be back when it's installed finish.

So right now the setup was successful.

So as you can see, the installation has been done.

So I can just click on Close.

Now for me to confirm evolve Python installed, I'm going to open up my command prompt.

So here in my command prompt, I'm just going to type Python.

Once I type it, you should open up this show.

You might not understand what all this is now.

But this is just to verify if Python was truly installed.

So now that we know we have Python installed, let's just go ahead and install our code editor.

So Python is the programming language.

But we are going to code we are going to program everything or the Python we're going to do is going to be in a code editor.

And there are various code editors out there.

We have Visual Studio code, we have pi charm, we have Sublime Text, we have atom.

There are counselors out there, but for this tutorial, we are going to be using Visual Studio code.

So let's go ahead and download it.

So I can close up my command prompt right now.

So let me just say if you don't know how to get your command prompt You can just search for it on your Windows search bar.

So right here, we can just go back to Google.

And then we can search for, let's say download Visual Studio code.

And I'll just click on the first one.

So since I'm on a Windows, I'm going to download the one for Windows.

If you're on Ubuntu or Linux, or Mac, download the one for your OS.

So right now you can see that it is downloading.

So I already have it downloaded on my PC, I'm just going to cancel that since I already have it downloaded.

Let me just show you the installation process.

So right here, I have it downloaded already, we just click on Enter does to run it.

So what it tells me here is that setup has detected the Visual Studio code is running.

So this simply means that I already have Visual Studio Code installed on my computer.

So I'm just going to press Cancel.

But for you, as a beginner, you want to install this as a new software.

So when we already have this installed, by just going to open up our Visual Studio code, and this is what it should look like once you first open it up.

So now we have everything set up.

We downloaded Python and installed it.

And then we downloaded Visual Studio code and installed it.

Now we can go straight into coding.

So now that we have everything stored, what we just want to do is to create a new file in this file is where we're going to code all our Python.

So in Visual Studio, good weather is going to come into the toolbar, and click on new file.

So once we click on new file, you can see it automatically as this untitled name, but I want to save it by pressing Ctrl S.

And I'm just going to save it.

First of all, let me say all files are there now to save it as up dot p y.

So the name of the file is up.

But at the bottom of the file extension, I used dot p y.

So anytime we're working with Python, anytime module, create a new Python file, it must always have the extension dot p y does will make whatever we are running on know that we are using a Python file.

So now once I save it is updated here.

And as you can see, Visual Studio Code automatically detects the logo of Python now does how to save grades and save a new Python file.

So this is basically how everything looks like in Visual Studio code.

On the left hand bar, we have four bar does we if we open in a folder, this is where we're gonna see all the files and folders in there.

We have this search this GitHub.

We don't need to bother about that for now.

But this is our Visual Studio code looks like.

So since we have everything we know how to create a new file, what we want to talk about now is the print function.

So in Python, we have some built in functions, that means some things that already done automatically, which we don't need to write too much of code.

Now let's say we just want to print us text to the screen.

Like we just want to show a user like a Hello World or welcome, we're gonna use the print function, it is going to bring some basic text to the screen.

Now first, to do this, we're going to say print, and then we're going to open parentheses.

And then we can use single quotes.

Or we can also use double quotes.

There is no problem here in Python.

But we can just go with single quotes.

So you can just pick one and go with that.

So in this codes, I'm going to write my text like I say, Hello World.

Now as you can see, I have printed hello world.

And I must make sure I save this file.

And then for me to run this Python file for me to see the output of my code, I'm going to have to come to the right hand corner right here and click on Run.

Now once I click on Run, you see that it opens a new terminal automatically.

And our code is going to be run in this terminal.

So if we just wait a second, we're going to see the output of this good.

You can see right here that we have a little word automatically prints hello world.

If I say hello world, welcome.

And I run it you see it changes and it says hello world welcome.

So does how to run a Python file.

Now let's talk about some more features about this print function.

Now, let's say we want to prints on a new line.

Hello world, I wanted to welcome to be on another line, we can easily do that, we can just remove these.

And then on a new line by just going to print welcome exactly the same thing.

Now once I run it, you can see says a logo down yet, and it says welcome, so does how to print on a new line, we can also do a lot of things, let's say we want to add another value to this hello world.

Like, let's print a sentence, let's say my name is told me.

And then I want to say my age is then I can add a comma right here and say 100.

So this will automatically tell Python that this is a number, and is no more a string, just a normal kurata.

So now once I run it, you're gonna see it says My name is Tony, my name is Andre, with no arrows.

And automatically you see the leaves a space right here, right here, we didn't leave a space, by automatically once we put this number year, it leaves a space to clarify that if I put don't leave no space, and I run it, you see that the spaces to do.

So that's just a smart feature of Python.

So I think that's gonna be all for the brains function.

Now let's talk about variables in Python.

As you can see, I have three prints function.

The first one says Tim is a boy.

The second one says team is 18.

And the third one says team is from Turkey.

So as you can see, in the three print functions, I'm repeating team three times.

Now we can use variables instead of repeating a particular text.

Now variables are just basically saving a data in the memory of Python.

And then we can get that data back by referencing its name.

So let's see this in action.

Let's say above the code, I have a variable named name.

So this name is the name of the variable.

And I'm seeing equals two, I put single quotes, and the name is theme.

So name is the name of the variable.

And theme is the value assigned to this name.

So like these, we've saved this variable up here.

So we can print that we also say print.

Whenever we are printing a variable, we don't put quotes like we do when we are printing a normal string.

So we can remove the quotes and just type the name of the variable which is name.

So now when I run these, you are going to see it prints all these.

And on the fourth line, a print team.

It didn't print name.

Now this is what variable is impulse is just basically saving a particular data and then referencing it drew the variable name.

So now instead of saying the same three times, we can just replace this team with name.

And for us to do this right here you see we printed only the variable.

And we didn't have quotes.

We're right here, we're printing a string with quotes.

And we also want to print the variable with it.

So this is called concatenation.

We're gonna join the variable and the normal string together.

To do these.

Let's remove theme.

And we're going to say name, which is the name of the variable plus the remaining text.

Now what is the name plus is a boy is going to print us theme is a boy.

So we can also do the same right here.

We just simply remove theme, I would say name plus is 18.

We do the same for the third line, we'll say name.

Plus is from Turkey.

Now once we print this, you can see it says theme is a boy Tim is 18.

Tim is from Turkey.

Well rightio said name.

So that's what variable is about.

So let's just type CLS closes up.

But variable is more broad than just this.

So there's something we call data types.

Now as you can see, this is just sim sim is letter is a corrector.

And that is a string.

So strings are basically just characters.

Now, string is a data type.

We have if this is a number like 23 is no more a string is now an integer.

We have Boolean which is for true or false values and oh This before this tutorial was going to be particular about maybe two or three.

So now, let me just undo that.

Let me specify a new variable and name it age.

Now this variable, I want it to be the age.

Let's give it a team.

So whenever we are using an integer or number, we don't add code when we are assigning the variable.

You see right here, we added codes, and inside our code we put team, but for it to be an integer, you will see that we do not add codes.

If I over on these, you see dices 18 is i n t, which stands for integer and then seem right here is a string.

So now we can just join these by saying plus H.

Now once we print that is still gonna give us Okay, so you can see now that this is can only concatenate string, not integer.

So now there is a problem with Python.

Anytime I want to concatenate a string with a variable, it doesn't, I mean, an integer with a string, it doesn't work.

So we can just solve this instead of using this, we can say comma H.

Once we press this, you can see it says theme is from Turkey.

So let me close this up.

Right here, we can see anytime we're concatenating we just drink it's possible.

But when we are dealing with an integer, we can't use this plus, we have to use comma.

And we can also use comma, we're concatenating with a string also.

So this is the two things, we can use additional sign with only string.

And then we can use comma with string an integer.

So if I run it is to go to work theme is a theme that does basically out to concatenate and join strings with variables.

Now we're gonna be talking more about strings.

So strings are just plain text.

So if I print something like print, alright, this is a string, string, or just plain text.

Now we're going to talk more about the features of strings, different things you can do with strings.

Now let's say I say I put a full stop.

Oh, you know, once I run this, you see that it runs it on the same line, which is I will you wave, I want this to be on another line without being put in another print function, I can just simply we use a backslash n.

This is a backslash n.

Now this is gonna automatically take these to a new line, it's just like a break, it's going to add a break in between these and these.

So now once I run it, you're gonna see he says, I, our you will have this piece here because of this, if I can Sadat and I run it again, you're gonna see we have I owe you.

So with also prints drink as a variable.

So let's see we have something named name, and the name is Tim.

So this is a string is a variable, both a string type of variable.

And then in print function, we also print that string variable by just saying print name, without quotes.

Once you print it, you're gonna see right here we have seen printed visuals close this up.

So if we come up here, we can also print let's say we want to add a double quotes or single quotes.

Now you know we can add a single quotes in between our text does because Python is going to see this like we want to close on this prints text.

So first we'll add the double quotes we can just easily add the bus slash then the quotes now once you have a blog slash, and that's good, this court is going to print it as I run it, you see now we have I with this good hour you so if you want to create special characters, we use the backslash, or you can just bring the backslash alone is gonna work.

So you can see the backslash is there.

So we can print.

Use them.

Last crash to break to make it on a new line, because there is a backslash to add a quote.

And then we can bring the bus slash just like that.

Now let me talk to you about special functions on strings.

So functions in Python is just a block of code, which does a particular task.

So in this string string gets a lot of function, which does different things.

Let's say we want to convert all the characters in this to uppercase, we can use a string function, we want to check if it's lowercase, or once we get on to the first letter, or the second, those are functions in Python.

So now, we can just say want to get only the first letter.

Now once we get the first letter, we can just easily do something like print name, square brackets, and zero.

Now zero represent the first letter, if I say one, it represents the second letter, if I said to represent the third letter.

So in Python, or in programming, in general, numbers start counting from zero.

So once I put zero and then run it, down here, you see it prints only t.

Now let me run to which is the third one, you see, it's prints only M.

And if I run what is not there, like 0122, I try to run theory is going to give us an error, index error.

So you can see string index out of range, which means it's not present.

Now it also do multiple things.

Let's say we want to convert these all to uppercase, we can just do name Dodd's case.

Now once we run this, it says as no attributes or by case, so sometimes we can run into error, we just change it.

So I think is because there is no supposed to be case.

So named oppa is the function that changes it to uppercase.

So once I run it, you see now that we have seen in uppercase, we can also do the same thing with lower, we just say named or lower, and then we run it, now you can see that everything is being changed to a lower case.

Now once we come back here, we can also check if everything which is present here is uppercase, or if all the characters are lowercase.

So for us to do that, we're just gonna say name.is, lower.

So as I run it, you see it says false, so it's going to give me a true or false response.

If everything is upper case, it's going to give me false, but it's lower is going to give me true.

So you can see, since there is an upper case t, I asked if it's lower, and it says false.

But if I ask if it is upper, I run it.

If this is false, that's simply because this upper case and lower case, not everything is upper or lower.

But if I change it to a lower case, let me change everything to upper m, and then I run it because the nicest true, because everything is uppercase, and they will also join different functions together.

Now you can see if I say something like is lower, and I run it, it says false.

But I can first of all, convert it to lowercase, then ask if it's lower, so I can do that lower.

And then run.

You see now it says true.

What is upper case.

So first of all, it says named don't lower, which means converted to lowercase, then it checks if is lowercase, which gives us true.

So that's basically how to just join different or add different functions together.

Along with also do something else by let's say we want to get the amount of characters we have in this variable.

To do the arts, we can say Len, then we open a bracket and close it.

When we run these, you can see it gives us three because we have 123 if I have a lot, and then I run it is going to give me a team the number which we have in the so that's how to get the length of a string.

But let me just undo that.

But let's say we want to find where at particular text ease.

So this is i less than want to get the index number of I, as we know this is zero, and one.

So this i is index number is one, if we want to get it, we're just going to say, Len by going to remove Len.

So I'm gonna say name, dot index.

And then we're gonna say I, so now he's gonna print me one, because as the index number of I, once I run it, you see, it's prints me one, which is the index number.

Now, let's say we want to replace a text, let's say we have m want to replace it with C.

So we can easily do that.

We're just gonna say his name, the Replace, I'm gonna open a bracket, Bertha parenthesis, then the techs to replace will not replace m are gonna put M.

And then what we just want to do is comma, and then what want to replace it with want to replace it with C.

So now, once I run these, you can see it's printed, see it.

So that is replacing this m with T code, that's basically how to replace.

So there are also a lot of functions, a lot of string functions.

But these are just shown, I showed you how to use them.

So that's gonna be all for strings.

In this part, we're going to be talking about numbers in Python.

So to print a number in Python is pretty easy.

We just type print, and then we just go ahead and type the number 78.

Now once we just run it, you'll see that it prints 78.

So we don't need to add any syntax or anything, we just print 78.

And it gives us 78.

Now we also specify a number, the variable can say, No, the number is equal to 79.

We just write the letter, we don't need to add these.

And then we can print number.

So once you run it, it gives us 78 and 79.

Now we can also add numbers.

So let me just remove this.

So instead of just printing 78, we can print 78 plus 22.

Now we got add a number, we can perform arithmetic operations.

Once I run it, you see that it gives me 100, it automatically adds these two numbers or integers together, and then it runs it.

I also try these with a decimal number is 2.7 days.

Then once I run it, you'll see it gives me 100.9 34.

So that is how numbers work.

And we'll also test it out with the subtraction.

Says gives us 55.066.

And then we can test it out with the division gives us the answer.

And then we can also test it out with the multiplication.

When we run it, it gives us the answer.

So that's basically basic arithmetic operation with Python, we can go further just what we did with strings, we can go further and use the beauty number functions.

So let's say I want to show the remainder of a division.

So let's say something like 20 divided by six.

Now you know that this will give us three remainder two.

So gonna give us three remainder of these.

Well, what we would just only want to get the remainder, we don't want to get the main answer, we can just do 20 percentage sign six, as I run it, you see gives me two which is the remainder.

Now does how to get the remainder of a division will also convert a number to a string.

Now let me show you.

Let's say we have this variable.

We have a variable named number equals to 55.

You can see that is a number an integer right here.

Then I can specify a new variable, I can name it number two, and I want this number to be a string.

So I'm going to say this drink of number variable.

So now, if I over on this number two, you're going to see that as a string, when I print number two is going to be 55.

But now we just shrink 55 also boys a string.

So how do we know if it's really a string? Remember that when concatenating yukako calcination numbers, wake up caucus needs restring.

So let's try to concatenate.

So right here, let's see.

Number is, let's try to call continue with the main number.

So let's say add number.

Let's run it, you see, it gives us an error can only call cause in a string, not integer.

So but now that we've converted it, this try to calcagni with non to, once we run it, you see that gives us number is 55.

So that's to show that it has converted that integer or that number to a string.

Now Python sees that as a string, this is also very useful in a lot of cases.

So does that.

And then we can also get the absolute value of a number.

So let's say let's just cancel this, let's print minus five.

Now, obviously, when we print, this should give us minus five, as you can see down here, and just closes up.

What if I wanted to print only five regardless of the sign, if it's positive or negative, I'm going to add a b s.

Now this is a function is a number function, as I explained earlier, function is just a block of a block of code, which does a particular task.

Now we can write a function manually by itself.

But Python has some built in function, which you can automatically use.

That's why when we use abs, it automatically sees it as a Python function.

Now this ABS means absolute does the full meaning of ABS, so we're going to get the absolute value of this number.

Now when I run it, you see it prints only five, regardless of this negative sign beside it.

So we have four and two.

So now you know that four is obviously greater than two.

So once I print these is going to give me four, this is showing the is number of DS.

So that means for resupport to or not for is for us to serve.

This means we have these two numbers, Max was going to get the highest number.

So let's say we have another number named three, once I run it is to print four, because four is greater than all of these for now what if I have 16 once I run it, it gives me 16.

Because 16 is the highest number in this range of numbers, I can also do the same to get the minimum amount of numbers, I can say m i n, so that is going to automatically print true because as the minimum so once I run it, you see it brings two so that's the basic way of getting the maximum and the minimum and then it goes around in number two.

So we can estimate a number.

So you know, in normal mathematics, if we have something like 3.2 this is estimated to three, but if we have something like 3.5 this is estimated to four we can also do this year in Python.

Suppose To do this we just a round the round 3.2 is gonna give us three was we round 3.5 is gonna give us for just normal estimation, rounding off to a number.

And then we also have one, which is been let's see beam.

So what this being does is that it converts a particular number to a binary string.

Now if you know binary numbers is this weird type of text.

So each number as is binary strings zeros it gets the binary string of a number Just run it, and it prints this.

Now let's run something like 334.

It prints the binary string for 334.

Now, that is some basic functions.

But they are countless functions for countless number functions.

So all these, we're not able to assess them, because we are able to assess them because they're already built in Python.

But there are still more that we can't assess.

Except we input.

Now there's something in Python called inputs.

Now we have more number functions, the one that is able to find the square root, the one that can get the power, various countless.

So now the reason why we can't access those one, because we haven't imported, the ones I just show you, we can use them without importing.

But the ones I want to show you now we need to import them from the Python mat function before we can use it.

So first to import, we're going to say from math, something like this.

import all voiceover writing Oh, right, esoteric.

So what this is doing is saying from the maths class, or the math function, import everything which is there.

Now in this maths class of fine john, it might, they might be the one that can find square roots, they might be the one that can find the power, everything.

So we don't know the one we want yet.

So we're just importing everything with this asterik.

So now we're going since we have this imported, we can find the square roots.

Now, we can just see square roots of let's do something like Andre.

Now once we run this, it will give us 10.

As you can see, give us 10.

Today, this point 00 K, but now it gives us 10.

So that's gonna be all about working with numbers.

So in this part, we're gonna be getting users input.

So what we're going to be doing is to tell a user to input a text, and then we're gonna save that text in a variable.

And then we're going to tell the user what input.

So let's go ahead and protocolized that.

So to use our inputs in Python is pretty easy.

We're just gonna say inputs, then open and close parentheses.

Now, when is open or close parentheses, we're gonna ask the user what we want him to input.

So we're going to put double quotes.

And in that code, we're going to say something like input your name.

So now this is going to tell the user to input your name.

And then once the user type in something like theme, or Tommy or john, anything users type, we want to save it in this variable called name.

So now this variable called name is going to be the input.

So now let's try that we run it.

You see now, the first thing he says is input your name.

Let me say to me, when I click enter, so nothing happened.

What does how to use our input today, just close, we can come back here and just simply print to the user.

Name.

So let's run it.

What is our input name? unsafe, Tim, you see the eye just prints team.

So we can make this more interactive by asking for the user's name.

And maybe asking for the user's age and then telling the user Your name is this and your age is this.

So we have we need to have two variables.

Second, the age.

So name equals input your name and then age will be equals input your age.

So what we want to print is, your name is and they just want to add the name and they will close that.

And they will say and you the age, years boat.

Now when we run these, it says input your name.

Let me see Joan, and is 105 years old.

So he says Your name is john, and you are 105 years old.

So this is basically how to just collect simple data from the user.

And then use it the way you want tell the user, your name is this your ages this.

So this is the basic concept.

You can also link it with how they do websites, like when you create a signup to a website.

And then they saved your name, your email and everything in the database.

And they later Do you welcome john are welcome, whatever your name is.

So just to link that concept is basically just getting the user inputs, and then storing it as a variable, in this case as a data, and then we can print it to the user back.

So does, too.

All you need to know about getting user's input will also make it more fun.

Now, when we get user input, you can see that the age is seen as drink, right, the Ice Age is string, but we want the age to be integer.

So we can convert this string into an integer.

So for us to do this, we're going to say i n t, we open the bracket, and then we close the bracket.

So everything is inside this integer function.

If I come back here, you see now that this has been changed to integer normal strings.

But now if we try to run these inputs, my name, I input a random age, you can now see it gives us this error can only concatenate strings, not integer.

So for us to be able to add age, you know what we need to do, we need to either convert it to a string, which we know what to do.

Or we can just use a comma.

So let's just remove this.

And then let's run it.

So let's input a random age right here.

random name, and age.

So now you see it works.

It says Your name is john on your 13 now does how to basically just get user input, use it how you want, and then you can pass that information back to the user.

In this part, we're gonna be doing a simple Python exercise.

So what we're going to be doing is a simple world replacement program.

So what is going to be happening is that a user is going to input a sentence.

And then let's say you want to change a word in that sentence or change something in that sentence, then we're going to allow the user to be able to do this.

So if a user inputs A sentence, like I am a boy, and he later wants to change our boy to let's say, a guy or something else.

So that's what we simply want to do.

So I'm going to ask the user for three inputs, the first input will be the sentence, the second input is going to be what do you want to change, and then the total input is what do you want to replace it with.

So let's get that on protocolized it.

Now the first thing we're going to do is just to have those variables.

So let's have a variable named sentence.

And I want this variable to be an input.

And then I'll just say, and your sentence.

Now, let me just print the sentence to the user.

Let's run it.

Now let's say the sentence I am a boy.

And he just simply prints that sentence.

We're gonna come back here, let's just say your, your sentence is I am a boy, which is going to be whatever the user writes.

So then, what we now want to do is to have another variable, let's say what one should be an input.

Now this variable is the word you use that wants to remove or replace.

And then we can say, and word to replace.

Let's say the word to replace.

And then once we have that is going to be stored in this variable named word one.

They're also going to have another way, let me work through.

This is going to be, what do you want to replace it with.

So let's enter the word to replace it with.

So now once we have all this, we're just going to print sentence dot replace.

That means we want to replace this with this open bracket to take two inputs, which is word one, the word wants to replace, and then word two, what we want to replace it with.

So what this is doing is that, let's say we have a sentence named I am a boy, then this word one is the boy wants to change, and then we're two it was one to replace it with.

So let's just go ahead and test it.

So right here is running.

Okay, it gives us invalid syntax.

That's because we forgot to add a plus right here.

Now let's do that again.

Right here, you can see says enter your sentence.

Now let me say I am a boy, now is bring to us your sentences, I am a boy.

And it says enter the word to replace so I want to replace this boy and enter the word to replace it with or to replace it with dude.

Now you see it's print, I am a dude.

So that's basically how to do a simple word replacement exercise.

It takes in an input, which is a sentence, and then it takes another inputs, which is what want to replace.

And then the third one is what wants to replace it with.

And then it's basically just printed out to the screen.

So I hope you understand what to do with deed in this part.

If you didn't, you can just go back and watch this part again, and make sure you understand before moving to the next one.

So in this part, we're going to be talking about working with lists in Python.

So when you're working in Python, you're going to be dealing with a lot of data, or you want to be able to know how to feed your data into a list.

So the list in Python is basically just a list of different attributes of different values fixed into a value.

So let's just dive straight into the protocol.

Now to define a lease is similar to define a variable.

So we can just give it a name of a lease, let's say, a list of countries, and I can name the list of countries.

And I'll just use the equal sign and the square brackets.

When we're defining lists, we need to use a square bracket, I cannot give you some inputs like United Kingdom.

I can also give it another lease like xe, Ghana, let me say Nigeria, let me give it one more value.

And I can see Australia.

So now this lists a list variable, it has four values.

So now once I print the list like this, I'll just say print.

And I give it countries, which is the least you see that he just brings me the old list the way it is right here.

So that basically the main thing you need to know when to find the list.

By list is more broad than this, there are a lot we can do with lists, like lists, I just want to get the first attributes.

Now each list has the index number, like this is 0123.

And so on, just the way I said earlier in this tutorial that in Python or in programming, General, numbers are counting from zero.

So the index number of this value is 0123 is just similar to when we have a variable, let's say we have a variable named name.

And we have to me so these as an index of 0123.

Now that's very similar to at least each value as an index of 0123.

Now we can just delete that.

Now let's say we only want to print these we don't want to print the whole list.

I can just do it like these countries with square brackets and are fixing the index number in between those square brackets.

Now when I run these you see now and that is brings me only United Kingdom.

I can also do the same thing.

Let's see how to print Nigeria.

I give it to I run it now you see Do you have Nigeria, there are a lot of things we can do.

Now, let's say once we get this, we just want to bring only n from it, we can also do that.

So other thing country's index number two, we can specify the index numbers in zero.

So once I run it, you see it Sprint's me and now what does this mean? It says countries gets the value with the index number 2012.

So now it has Nigeria.

And then I say from that Nigeria gets me the one with the index numbers zero.

And then we see in Nigeria, n as index numbers zero.

So that's basically I'll just add some simple things in Python, Python lists.

Now let's say we just want to get only all the lists from Ghana to the end, we don't want to add United Kingdom, or we just want to get the list from Nigeria to the end, we can also do that.

So we just say countries want to get from Ghana to the end, we can just say, our square bracket, one and a column.

Now this is going to get everything from index number one to the end.

Now let me show we close this.

When I run it.

You see now it gives me the list without United Kingdom does lt just get it from a particular index number to the end, we can also do the same thing we can see from to use it again, from Nigeria to Australia, right here, Nigeria, and Australia.

Now I also specify a range.

Let's say I only want to get the list from one to two.

Okay, let me add one more value year, let me say New Zealand.

Yeah, so right here, I say New Zealand.

And this is 01234.

Let's say I only want to get from one to three, I don't want the last one.

And I don't want these, I can easily do that, let's say from one, which is from Ghana, index number one, that after the column, I'll say three.

So 123.

As I run that, you see our K, it gives me Ghana and Nigeria.

So this is 0123.

Okay, so let's say two, four.

I, when I run this, it gives me Ghana, Nigeria, and Australia.

So it gives me from here all the way to three.

So this is basically going to get from one which we started to the one before which we end.

So does how to do that in Python.

And then we also get the type of the list.

Now if I print something like type countries.

Now it's going to print to me that this is a list down here.

So let me just type CLS to clear everything I've done.

Now let me print it, you see says class lists.

So this is showing me that this variable type is a list.

Now it is just a normal variable as a string variable is also going to show me that it is a string.

Now let's try that.

Let's just divert from least for a second.

Let's say we have name.

So me and I said that type of name.

When I run it, you see down here it says a string.

If I change these to 12 you will see down here it says integer so does how to get a type of a particular value.

So those are we know now that this is a list variable.

Now I can just simply delete that.

And then let's say I want to change the value of one value in this list.

Now let's say I want to change this from United Kingdom to United States.

So what I'm just going to do is just say, countries zero because the index number of United Kingdom is zero should now be equals to United States.

And then let me just add a print maybe print countries now when I print countries Okay, you see name is not defined as because we've removed this very good I was gardening.

So let's just remove this line.

I run it again.

You see now the first value is now United States.

Meanwhile, his United Kingdom right here, but that's simply because we change it.

The United States here can also do it again, let's say we want to change Australia, which is the third, we'll say, three, unless they want to change Australia to a country like Canada.

When I run it, you see, we have the United States, Ghana, Nigeria, we don't have Australia, again, is not Canada, then we have New Zealand.

So that's how to change a particular value in our list.

Now, let's say we want to get only the end of this list.

You know, we can also get it by just let me just quickly delete all this, we can get New Zealand by just typing countries, which is index number, which is 01234, New Zealand index number is four by type four, and run it, it gives me New Zealand.

But I also do it in another way.

Now if I add a negative sign right here, let me delete these.

And I say one.

Now this is going to get the least from the last value in that list.

Now if I run this, you see it gives me New Zealand, if I see minus two minus two is obviously Australia.

By run this now, you see we have Australia.

So note that when you're using a negative sign, it gets you that list from the last from the bottom, basically.

But you notice that from the beginning, we use zero for the first, and then we'll get started for the last we use minus one.

Yeah, that's because as we know, in normal math, zero is neither negative nor positive.

So when we start from the back, we use minus one, not minus zero.

So we start from the front is zero, we start from the back, it's minus one, so does how to basically use that.

Now there are also a lot of other things we can do with list, like we can get the length of this list, let's say want to get how many values we have in this list, because most of the times you have large amount of data can start counting them one by one like these.

But you can just say le n countries, which is the name of the list.

Now once I run it, you see gives me five, which is because I have five values in here.

But note that when it gives me the answer, it doesn't use me based on index value.

Now index value is just like the ID assigned to each of these values right here.

But when I calculate the length, it gives me the actual amount we are via which is five variables are calculated from the index number into before, I hope you understand that, we can also do some other things like in the list.

As you can see, all of these are strings.

Now instead of printing strings, let me just delete this New Zealand.

Instead of printing only strings, I can change, let's say this Ghana, I can change it to a number like two.

So now we have the string, we have an integer, if I print these, okay, this gives me four.

So let me remove length.

Once I print these, you see, it gives me what I want to see, if I bring the index number of these, which is one.

And I press run, it gives me two.

So we can mix different data types in a list.

I can also change this Nigeria to true, which is a boolean value.

Once I run it, let's remove this.

I run this, it gives me that so there is not going to be error, nothing is going to conflict, we can just easily do that.

And you remember that we checked the type of a list.

So right here, once I run these, you'll see that it gives me class lists, which means this variable is a list.

But let's say I want to check the type of the values in a list like I want to check the type of this value or the type of this value.

Now as you know this value is a string, it is an integer, this is a boolean value.

This is also strings.

Let me over on it.

You see it gives me i n t which is integer on one side over on these Let me see.

k doesn't give me anything there but this is a boolean value.

This is a string.

So let's say I want to get this, I'll just say type country's square brackets, and I give you this index number.

Now when I run these, you see it says class is a string.

Let's say I want to give for the second one, which has an Indian's value of one.

Once I run it, it gives me integer.

Let's try for the third one.

It gives me a bowl, which means Boolean, so does how to basically get the type of a string.

And we can also do some other things like, let's see, the last thing I want to show you for this part is another way to define a string LMC to assign a string, I mean a list sorry.

So instead of using the square brackets, we can also use something we call lists.

But now when we are using this list constructor, is called the list constructor, it is used to construct a list, where I'm going to use square brackets again, we're gonna use normal round brackets like this.

Well now, so let me just delete this line.

Now let's use the list constructor to specify how to construct a new list.

So I'll say list.

And I'm gonna use normal brackets parenthesis, and it has to be double.

So when I'm using the list constructor, it has to be double like this.

Now you can have all my values like Nigeria, I can have the default before, I can have false, almost, I print these, we don't want to print type, we just want to print everything.

country's nice, it gives me everything which I want to see.

So does how to basically use the list constructor to specify a list.

So we can print a list in two ways, the normal and the second list constructor.

And then we can also print them with a normal way without lists like the square brackets, like these countries too.

So now, if I said type, grants, the type of countries you see is gonna give me least.

And then let me also print the type of countries to just to show that both of them are still lists, so lists and lists, so that it will be all about the basics of list.

In the next video, we're going to talk more about lists, attributes, there are still a lot of things we can do with least in this part, we're going to be talking more on least, specifically, we're going to be talking about lists, functions, or least methods in Python.

So in the last part, I showed you about lists and plenty things you can do at least 20 list attributes.

In this video, we're going to dive more deeper.

Now let's say we have two lists.

The first one is list one.

And this list one is just a bunch of numbers 12345.

And then we have list two.

And then we want this list to to just be let's see a bunch of fruits so we have a banana and then we have abuse men goes unless you're English.

So now we have these two lists.

Now let's say we want to join these two lists together like we want to print it together.

We are going to do something like list one dot append dot extend want to extend it with listen to now also drains least one What is this gonna give me is the these joint with these.

So let's print it.

radiates you want to drill for five then banana, Apple mango oranges.

So just give me these joint with these the first least joint with the second list.

So does Wood stained doors, it combines the two lists together.

But let's say we want to add a value to the ending of this list like oranges.

Move on to add water, what do we have? I think we have cherries, but we just want to add something else to these.

We can do something at least two dot append.

And then what do we want to append to it, let me say cherry.

Now we'll say print list true, you're gonna bring me all these with Jerry.

Now Jerry is part of this list will see not only bananas, apples, mangoes, oranges, and it pains me cherry.

Now if I see I want to get the length of list two.

Now we have four year versus we appended one, it should give us five.

Now you see we are five.

So that just see is a simple way to append a value to a list.

And it's very, very useful also.

But let's say we want to put in a value in between one of these, like we have multiples in a value in between banana and apple.

This cherry, we want it to be right here, something like this.

Now if we want to do that, we're just gonna say lists two dots insert.

And then this is gonna take two inputs, now it's gonna take the index number, the index plays, we want to put it want to put it to one, and then we want to put the ACE cherry.

Now let me explain this further.

So it says list two dots instead want to say in the index number one, that means right here, then cherries should be right here.

So 01 want it to be want to input cherry.

Now when I print Jerry, let me just run this, you see now we have a banana then we have cherry in between.

So in between bananas and apples, we have cherry.

So that is how to insert a value in between a list.

But now let's say we want to remove a particular value from the list, we can say this to dot remove, alleges remove bananas.

Now once I print list two is going to print me and list two, without bananas.

And that's very easy is just by saying remove, then whatever you want to remove.

But now let's say we want to do something I want to delete everything in this list want to clear it up, you can just say least two dots clear.

And nothing is gonna be in here.

As I said at least two dots clear, this is going to be empty, it's just going to be an empty list.

It clears everything deletes all the values in the once I run it, you see not I placed me on empty list.

So does algae just delete a list? Very easy.

But now let's say that we have these values.

And the mango, we want to get the index number of mango, as we know this 012.

So the index number of Mongo is two.

But we want to get it let's say we have 1000s of lists of values in this list.

Want to get with the Mongo is located in that list, we're just going to say print list two dot index of mango.

So you just gonna print the index number of mango.

There's just run it right here you see is these 2012.

So it tells me where Mongo is located in this list, which is very, very helpful.

Now let's say we have a value appear in more than one.

So we just want to know how many times a value appears in this list.

Now it's very easy, we're just going to see is list dot count.

Mango.

So now it should tell us one because mango only comes in this list one time.

Once I run it, you see here we have one.

Let me come here and input mango again.

Now once I run it this time, you see that we have to because mango is in our list two times.

So that's how to simply do that.

But now let's see we have a list of numbers unless they are scattered like let's say we have one yeah And let me just delete all these we have four, five, so we have three year.

So 4351 unless I have to at the end.

So let's say want to print this list in ascending order.

You know, as I said, in Python, you might be working with a lot of data, and we have 1000s of numbers that are scattered, I want to print them accordingly.

Let's see from Andre wants to print to 250 to 350, accordingly, not scattered, we can easily do that was going to say, is least one dot sought, like this, right here, I'm just gonna print least one.

Now once I print, it is not going to print it 43512 is going to print 12345 in ascending order.

Now you see now we have 12345.

This also is very useful when working in Python.

But now let me just remove this mango, we don't want to have it twice.

That was just for testing.

But now let's say that we want to print a list from the back want to reverse the list.

Want to print it from the bottom, what we're gonna do, we'll say lists to dot reverse.

It's very easy, we just released two dot reverse, almost to print list two, you'll see that it's printed from oranges, then two mango, two apples, and two bananas.

Let's run it.

Now I see oranges, mango, Apple banana models, how to easily print a list from the bottom from the last value in that list.

Well now let's say we want to duplicate a list, like we want to just take this list and copy it again or something like that.

Let's test the four lists to let me delete these two, let's have another list named list three less than we wanted to list three to just be exactly the same thing with this in duplicate of list two.

So we're just gonna say is list theory can be equals to list one.

list two, I mean does copy.

So just going to copy all the values in this too, and then paste it in history, I was referring to this theory, I run it, we have exactly the same thing we get when we print listen to this exactly the same thing.

And then we can also do something more fun.

Like let's say we just want to delete the last value from these I just printed everything else.

We can do that by saying guys that by saying the pope method, so we can just say lists two lists two dots, Bob.

So when we say the student Bob is just going to remove the last value we have in Dallas, it will delete is going to remove the last value we have in that list, and then relive the rest.

So when I print these two now, if only three values.

So now you see we have bananas, apples and mangoes, no more orange.

But let's want to be specific, we won't want to delete, you remember that we can those remove a value by saying these two dots, remove an avocado specify tlsa banana.

And then when we print this, it will remove banana.

But we can just also delete or remove a value by using the index number.

So in pop, we're going to say list dot pop just like pop out to remove something.

Let's remove the one with the index value of one or say one and print us banana mango oranges.

It gives us that same list but without the value of that index number.

But we can also use doodies.

Instead of using pop, we can do this exact same thing.

But now we can use delete.

So when we say d L, I will say least true.

Let's say zero.

So now this is going to delete the value with the index number zero in this list two lists.

When we bring list two, they're going to give us everything without banana.

Let's run it nicely.

We have apples, mangoes and orange.

I remember that we also showed you how to just clear lists, I will just delete everything in our list.

We can also do this using this d l function.

So instead of specifying something here, we just say delete the L Listen to.

Now this thing is going to be clear this list.

Once I run it, you see it says list two is not defined.

Okay? But we do have list two right here.

So let's do something like, delete just one.

Yeah.

And then they just print.

Oh, okay, so um, the reason why it says lists to not defined, you can see we have list one, not here we have list two, which has banana, apple, mango, and oranges.

They were just doing with deleted list two.

So once we delete this list two is quite different from the one we did earlier, which was list dot clear.

Remember that if we do list two dots clear is just going to remove everything here.

But that list is going to be available in our code.

But when we use this delete is just going to delete a way that list is going to delete that value.

So it's not going to be in our code again, that's how I will not try to print list to Python does it seeds, again is a list two is not defined, so it completely removes it.

So there's a difference between the clear function and the Delete function.

Now there's going to be all four lists for now.

In this tutorial, we're going to be talking about topples in Python.

So topos used to store multiple items in a single variable.

So you know least which we talked about in the last but topples are very similar to lists.

But there are some basic difference, like tuples are immutable.

Now immutable means you can't change any value in a topple.

Now let me show you how to write a topple in Python.

Now let's say we have a total of three numbers.

I'll say three underscore numbers.

And I give those numbers, I want your writing the top, which means a normal bracket, no square brackets, so 123.

So let's say we have this now when we print three numbers around that, it just gives us this top bar, we can also do some things like get the first value in that Tapu using the index number, I can say get me zero, which will print us one.

So we can also do all those type of things.

But let's say we now try to change the value of two to something like 25.

It's not possible because as I said earlier on, it's immutable, which means we can't change it.

Once we have the top who does well is going to be for our code, we can't refine it or add anything from the top level later in the code.

So let's say we want to do something like three numbers.

Announcer from the index number one, change it to 23.

And then I want to print three numbers.

Now this is going to give us an error.

So yeah, it says type error top object does not support item assignment.

So he's saying what we want to do top who doesn't support it.

So that's the basic difference between topple at least.

And then we can also do some other things like topples allow repetition of numbers or repetition of values, like I have 123 uttanasana input one again, when I just let me remove this line, I have one twice, once I print that is going to work fine, it allows repetition of the same value.

And I also do some things like I can get the length of a toggle, I can just say print le n and then it's just going to give me the amount of values we have in this top.

As you can see it prints for because we have 1234 values.

And then I can also get the type just to make sure this is a top like a gundu type to know if this is a top or not.

Once I run it, you see this class top.

So that shows me that that is a top and top also allows various data types.

Like I can have another top and see strings.

And then I can say oh lunch.

Let me give you one more.

Now once I try to print strings, you see that everything works fine.

So it allows various type of data types, we can also do it again for like the Boolean type, I just say B Oh, and the less true or false, and then true again.

Now when we try to print B Oh, you see that it works fine.

So it allows various data types.

And then it doesn't just allow them on separate variables, we can mix them together, like know we have one, I can have another one, which will be a string, which will be own.

And then I can have another one, which is going to be a Boolean.

So once I print the first one, we just three numbers.

Now you'll see that everything still works fine.

So topples, allow all these kinds of things.

And then in tacos, we can also check the data type of the value of that taco.

Now we want to check the data type of this face value, we can say, type of three numbers with the index number zero, which is the first one, they should bring to us int, which is integer.

So as you see it says class int.

Now does topple can also do that.

Now, instead of just writing these parentheses right here are normal brackets or circular brackets, anything you want to call it is totally fine.

We can also use the topic constructor, just the way I told you about least constructor there is also a topic constructor.

So the only difference is just our going to add a pool right here.

And it will have two brackets like this, as I tried to print everything, still gonna be fine, let me just print the top of variable normally.

Now as I printed, you see there is still a top, nothing goes wrong.

And that's gonna be basically all about topples the basics of tuples in Python, so we might be using this topples less often in Python, who mostly use lists.

But in some cases, we really want to use tuples.

In Python, something like let's say you're working with coordinates, or just some numbers that you don't want to change, or some values you don't want to change, I suppose might be the best option.

In this tutorial, I'm going to be talking to you about functions in Python.

So functions is just a bunch of code which perform a particular task.

Now functions allows you to package your code Well, let me say restructure goodwill is just like a block of code, which performs a particular tasks the way you want to use the function, you just call it.

So let me show you how to do a function in Python.

So for us to define a function, we're going to use a keyword called def.

Now once we type this def, Python knows that now we want to define a function.

So you can say d f, let's just do a simple function, which is going to greet the user.

Maybe it will say welcome or something like that.

So we can just say greetings.

So now, the key word, which is def, and then after it, we have Greetings, which is the name of our function can say greetings underscore function.

So this is the name of our function, and then you're going to be followed by open and close parentheses, and then after it are going to have a colon.

So after this block of code, Python knows that whatever is going to come below it is going to be the task in which we want that function to perform.

So once I click enter, then I notice that it doesn't start from beginning it starts right from displace, automatically it indents now in Python, indentation is very important.

So now this indentation shows us that whatever code we're going to write, let's like print something is going to be on the dysfunction.

But if I just removed indentation, and I start from here, then the function is cancelled.

This is an invalid syntax, because normally there's supposed to be an indentation and an indentation, one indentation, it goes to four spaces.

So if I go here, you can see is 1234.

So once it indents automatically automagically.

That means it's created for species.

Now let's say you are using a code editor which doesn't does the indentation automatically Like if you're using Notepad, and then once you click on Enter, he doesn't add the indentation, you can just ask for space like this 1234 that does automatically indented.

So now we want this function to just tell the user welcome or greetings from me or something like that.

So can you say welcome user.

So like these, this function named greetings function is sprinting to the user that welcome.

But if I run this, nothing is done.

I'm just closes up.

And why is that.

So when we have a function for that function to be performed, or for that has to be executed, we need to call the function.

And I will call this function we can just say, Now, once I press enter, you see it's still indented.

But I want to go to this function, I'm done with what I'm doing in this function.

So if I just press A Backspace, now, this is out of this function.

Now, if I just say, greetings, function with open or close parenthesis, now I'm calling this function.

So that means this is girl is just the same thing as everything we have in this function.

So now it should print a welcome user.

Also just run it you see now it says welcome user.

So that is how to use functions in Python.

But functions is more broad, there are a lot of things we can do with function.

Now as you can see, this then says welcome user the result.

But which user let's make it more fun, something like that, we can pass in something called arguments or parameters.

So right here in this open or closed parentheses, instead of just leaving him blank with compassion, something like, Um, let's see, we have name.

Oh, not this.

So name, which is the name of the user.

Now, instead of saying welcome, user, want to say welcome, name.

Right here, we're just gonna say, name.

And this is just gonna print welcome name.

But instead of name, it expects us to pass in something when calling this function.

If I just run this, you see, it gives me an error.

It says Greetings, function missing one required positional arguments name.

So this is showing us that when we're calling this function, now, we need to pass in wolves Eva user that is, so let's say the name of the user is john.

So now when I run these, right here, you see it says welcome join.

So let me just go back and make sure to explain it very well.

Right here we have this function, it's having an argument or parameter, which is name.

So this name is going to be able to tell the function which user it wants to greet.

And then it's just going to greet the user with the print function.

So for us to give it this name, this name is just like a variable.

So when we're calling the function, instead of leaving these blank like these, but I was going to pass in the string like john, but you know, we can also pass in other data types.

So you can see that this john is a string.

But let's say we just want to pass in an integer or a number.

Or, you know, anytime we're dealing with numbers in Python, we don't need the quotes, we can just say 34.

Once I run these, you see it says can only concatenate strings, not integer.

So if you follow this tutorial, from the beginning, I showed you how to convert an integer to a string.

So right here, it says if count, concatenate string an integer, that means you can add them both together.

So for us to be able to use these, we must make sure that we convert this integer to a string.

So I'm just gonna say string like this.

Now this name is a string.

Once I run it, he says welcome pitiful.

So that is how to basically do that.

knowledges go back.

So let's do make sure we're passing in john.

So that is how to pass in parameters or arguments.

Now you can call it parameters.

You can call it argument, whatever you want is fine.

And then we'll also pass in more than one parameter or argument.

So we can pass in name can also pass in age.

And then we can say welcome then the name.

And then we can say something like let's do these you typed the name, let's see, age.

Yes board and a full stop.

So right here, when we're passing in these, john, we're going also passing the age as an integer is C 27.

But remember, now this is an integer.

If we run these, obviously, we're going to have an error, which is cannot concatenate string and integer.

So you know that we now have to convert this to a string right here.

And then run it.

So you see it says, Welcome, john, you are 27 years old.

So does what does how to simply do that, you can pass in two arguments or parameters.

Now, let's say you don't know the amount of argument that's going to be passed in you.

Let me particularize that Before explaining.

Now, let's say we have names.

Let me just remove all these this.

Welcome name.

So let's say we have these.

Well, we don't know how many is going to be passed in here.

So we're gonna have to put something like esoteric.

Now this asterik is showing that we're passing various amounts like a tuple, a topple of which is like a list of values we're passing in here.

And then we don't know the amounts that is being passed.

So let's say right here, we have this topple, john.

Let's see, we also have another one named, Tim.

Let's give it one more.

Okay, right here.

One more named Tom.

So right here, we're passing this tree list these three values a year as names.

So these names is like a topple now, that's always a steric.

Because we don't know.

So for us to now show the name, which we want.

Let's say we only want to grease the second user, then we can create the user using its index number.

So you can say names, the index number is one.

Now when I run these, you see it says welcome, Tim.

So does how to pass in various values, more than one value if we don't know what we are passing.

Now, let's just go back.

Let me press Ctrl.

C, but to name and age.

Quickly, okay, like these.

Yeah.

So let's print this and make sure that our code is working.

Welcome, john, you are 27 years old.

Right.

Now, we can also pass this instead of just passing the values we can pass is true, the variable names now catches up to like name is equals to john.

And then age is equals to 27 is still exactly the same thing.

So when we run it is still going to print those welcome, john, you are 27 years old, is basically the same thing.

So let's make this more fun.

Instead of just passing out these values, statically, or by just add code into values, we can first ask the user to give us an input of his name and his age, then we're just going to print that.

So let's quickly do that.

Right here.

No, right.

Yeah.

So right here, we can see name, inputs, and your name.

And then let's give it another one named age.

inputs, MSC and your age.

So now asking the user for the value is one I'll just type in these.

And then once the user give us these are those gonna replace that year? So by placing it with name, and replacing this with age, so let's run this.

So if I come down here, ask for my name.

I say team, it does for the age, I say 101.

Now it says welcome team.

You are Andre, our.

So I hope you get the concept of functions in Python.

These are the basic thing you are going to be dealing with in Python.

In this part, we're going to be talking about return statement in Python function.

Now return statements are just being used to get a response from the task being executed in a function.

Now, as you know, in the last video, when we define our function, then we just simply printed out whatever we want to return.

But normally, in Python, we use what we call a return statement.

So this return statement is gonna like give us an output or give us a feedback of what has been executed.

So let's personify this right, let's say you are, you are being sent an errand to go, let's get some information.

And then when you come back, you want to give a response or you want to return like a feedback, you want to say what you want to get, or the task which you executed.

So that's the same thing right here in Python function, decode block, goes for the errand, and in the return statement, give us a response.

So let's show you how to do that.

We're just gonna define a normal function, let's just say my function.

And then it's not going to take in any argument for now.

So in Yeah, we just want to return let's say, five blows four.

So this basic function now is just simply going to return nine, because that's 5.4.

But now, if we can just print out my function, so once we print out my function, you see, well, it says function, my function is just you know that as a function, but we also need to add our open and close parentheses, when I run it again, we see nine.

Now we're gonna make this like more interactive, we can just have a function that adds up to numbers or subtract numbers or something like that.

So we can say, add numbers.

And then want to add two arguments, number one, and number two.

So what we just want to return is number one, plus number two.

So right here, we can just passing no more number two, and number two as three s3.

So this will give us, you see, says my function is not defined as because we've changed the name to add numbers, we're just going to run it again.

You see, now it gives those five.

But let's make this more interactive here.

Let's say number one, is equals to input.

And first number underlays, avinoam.

to aim boots.

And second number.

All right, yeah, so same to give us number one, right here we'll give is number two.

So now when we run this is going to ask us for the first number, let's say 80.

Or let's say 20, as the second number is going to add this up and give us 100.

Now it is you see it says 88 8020.

And the reason why it says this is because it's seen these as an status drink.

And so, when we use the addition is seen it as concatenation.

So as I just said, 8020, but I wanted to add you by coming out over very juicy says the stringed Well, we know we are collecting an interior what Python does, you know that so, we have to tell Python that a what you want to collect is a number.

So I want you to add it to do that convert it to an integer by saying i n t.

Now, we close it right here, then we also do the same thing i n t and then we close it right here.

Now, when we run this is going to add it for us at this 20.

Now it gives us Andrea.

So does the basic concept of return statement.

And I also want to point out something that whenever wisened return statement in Python function, we do not write anything after that code block.

Like that return statement shows the end of the function Call me an hour save print.

Hello.

Once I run it asked me for the numbers, you see just gives me 80 just return these, it doesn't print a low, because it is outside our function and is not a normal indentation.

So that's code is not seen in our code block.

But if I come here, if I delete it on inside the function, I paste it is going to print that for us.

So let's say for for now you see we have Hello, and then we have the answer of the audition.

So that is how to use return statements in a Python function.

In this part of the tutorial, we're going to be talking about if statements in Python.

Two if statement is basically just giving Python a condition.

Now, this concept is very easy to grasp, not only in Python, but in programming in general, there is always if statement, but maybe with different syntax.

So if statement is just a line Python to execute code automatically by itself.

So assuming that if a particular condition is true, then Python should do this.

But it is not true, then Python should do that.

So why does give me Python a condition before it runs the code? So let me first type a simple little notes so you can understand the concept.

So I can say something like if I write a number, so now I write a number.

And then if the number is divisible by two, then we know that the number is an even number.

What if is not divisible by two, then it's an odd number.

So something like this, this is not how to write code.

This is just plain text.

But I'm just showing like yeah, use I wrote a number, then if the number is divisible by two, then we can tell Python to tell the user though, okay, this number is even.

But it is not divisible by two, then this number is odd.

So now let's protocolized is on his right, it's a real Python code.

So now we have a variable named a is equals to true.

And then we have another variable named P and b is equal to three.

Now go have a simple if statement.

checking if two is greater than three or three is greater than two, or if variable a is bigger a variable b.

So say, if a is greater than b, then we can just print to the user a let's go catenate is greater than B.

Okay, boy, yeah, we know that b is greater than a.

So let's just make this greater.

So cool.

We run.

Now let's run this.

Now you see cannot concatenate string, I know those types of stuff.

So let's just convert it to a string.

So let's run this again.

You see now it says four is greater than three.

So we checked if a is greater than b.

Now it also check, obviously, if b is less than b.

Now you see that nothing happens.

Because we said it should run this code.

Only if a is less than b versus is not less than b, the good news a cuted.

Now we can also check if A is the same thing as B.

So if b is equals to B legends make a equals to B.

And we run it.

You see it says four is greater than four because that was the third issue, say, but we can just simply say A equals B.

So as you run you see is this A equals B, where we change is now to three.

Now four is no more equals to three.

It doesn't run.

So that's the basic concept of if statements.

I will also do this for different data types.

Now let's say we have a string, which is Team B is also team.

So now we know that A is equals to Team A, B is equals to team.

So obviously a is the same thing as team.

And then you say A equals to B.

When we run it, you see it says A equals to B, then we can also use the Boolean.

So let's say true.

Now we can see if a is equals to true, that means if A is true, then we can just simply say, A is true.

And then we can just run this.

So A is true.

So does the basic concept of an if statement.

Well, you know, we can also say if A is not true, that means is something like false.

They will say a is not true.

So you know now is false.

When we run it, he says he is not true.

We can also add two different types, like if let's quickly change this back to integers.

So let's see, if a is greater than or equals to b, so you know, a is greater than B.

Or if a is greater than or equals to B, then we'll say ratio say true or something like that.

So let's run it, you'll see says true because A is greater than B.

And if a is also equals to B, it resists a true because A is equals to B.

But now let's say a is less than b.

When we run it, nothing has been executed.

So now we want to add more functions to this if statement.

So it says if a is greater than or equals to b, so let's just check if A is equals to B, no, say A equals B.

But what if a is not equals to be watching the Python two? What should the cause do? Surely Joe's not run anything? So we can now add else this else means if a vigils correct this, if A is not equals to this, so as an IF is equals to B it should print A equals B else means anything except that, then she just print a not equals b.

So if a is equals to B bring this, then else means if it's not the opposite of that, then issue just print a is not equals to B.

So when I run these now it prints a is not equals to B.

So that is how to use a simple if an else statement.

We can also do that with like a Boolean, does make this true.

So say if A is true, let's say A is true.

If not, let's say not true.

So when we run it, you see says A is true, with our changes to false.

Obviously a is not true.

So it says a not true.

So that's how to basically use a simple if else statement will also go further.

Now let's say want to add more than one condition, like if A is equals to true leaf a is equals to false.

Print A is false.

Else is known of the two.

So if a is equals to true it should print A is true.

A leaf means require adding another statement is the same thing as if both else if does mean you have if so if a is not true, then you cannot check if A is false.

So if a is false print this bereave is none of these two, then just print a is none of the two.

So now it should print a is false when we run it across You will see a is false.

now know how to add a simple elsif statement.

Now we got add any amount of Elif statement want to add, we can say, Canada when I say leave a, let's see not equals to, let's see.

A something like that, then we can print we can just bring anything wants to do.

So it got any amount of Elif statement is, does the basic syntax and we to use an if else statement.

But now we can make this more, we can step up a little.

Now instead of saying if A is equals to true, so we can say, if A is okay, let's let me specify a variable, let me see.

Boy, is true.

Let me say short, is also true.

So I can say if boy is true, then print is a boy.

Now, since boy is true, right here is nothing like that.

So let's just change this to boy, since boy is true, then we can say is a boy, we can also do something like if boy is true, or shorts is also true.

So that means if any of these two conditions are true, you will print is a boy or he is shot.

So when I run the AGC is a boy or he is short.

So since both of these are true, his prints this, if this is false, it still like he was saying, If boy is true or short is false, is still going to print this.

Now the reason why I still printing this is because all we're raising the O is going to check for only one.

So if one of these condition is correct, he just runs this.

So when I run this, you see is a boy or a short, both, if I change this now to and you see that it doesn't print this, it will print a is none of the two.

So let's just remove this else if for a while.

So now you see that it prints the L statement a is not only two.

And that is because we're realizing and it has to check that these these conditions are both correct.

So if one of it is not correct, is just going to go to the next statement and skip that statement.

So that's different between all and and so now that we know the concepts, the basic concept of if else, and Elif statement, let's just go ahead and do some simple exercises.

Now let's say want to use FL statement to check for the data type.

And until the user Okay, these data type is, let's say a string, or it's a lease, something like that.

Now, first of all, let's do the user to input something.

So let's say value should be input.

And they will tell you user inputs of value.

Now once user input a value, we're gonna check for the value and tell the user that oh, this is your value.

So we can use an if statement for that.

So we want to check if the statement is a string.

So we can say if type.

If the type of value is equals to a string, str, then we'll print.

Let's just print out value value is a string.

Well, let's add an Elif.

Let's say we want to check if the type is an integer.

type of value is an int does an integer, we will print value is an integer.

And then we also want to check let's see if it's a list to say a leaf If the type of value is a list, do print See, value is a list.

Ball is none of these, we just say, we don't know.

So right here, I wanted to add this, but obviously it says, Python says I've closed it.

So for me to add this calendar codes there, I have to use the backslash.

So now once I use plus slash is going to be printed with it.

So now we can say we don't know the date, I have the measures or whatever they use our routes of value.

Now, let me just close this quickly.

And then let's test this out.

Now we input the value, let me input six is this six is a string does nice to year.

Now the reason why this is a string, because anything we put automatically gets it as a string.

Now, if we want to get this as let's say an integer, we have to type int, we have to convert it to integer.

So this type of exercise only works for string.

So now we're changing the name of this exercise to check in if it's a string only.

So what we just want to do is we cancel this, we're not checking for age or list or any other data type, we're just checking if it's a string.

And that's because Python automatically sees it as a string.

And we have to convert it to an integer if I don't want to know if it's an integer.

So we can also go for that to check in with an integer by using some complex if statement, or some reg x we usually don't need to bother about for now.

But for now, let's stick to this basic exercise.

So we're checking if it's a string.

So if the string who says the string is not to say, is not a strange.

So we just bring all these to the tub.

So right here is where it should be if a space and then there's run it again.

Now when I print the value now, and I say, I know you can see that I guess that is a string.

So that's basically how to just, you know, do it.

But if we want to, like change it or save and say integer.

So now anything we input is automatically seen as an integer.

So it will automatically say value is not a string.

So even let me pull six.

Now I say Conoco cut, nice drink.

So that's simply because we have to convert this to string before concatenating.

Or, let me show you a better way to do it.

Since we're just dealing with one.

Instead of using plus here, I can just use a comma.

So when I run this, again, I input an integer, he says seven is not a string.

So now the second is a size we're going to do is to check if a number is divisible by five.

So we knew that we have numbers, multiples of five, or something like that, that means the numbers which five can be divided by So we have five itself, we have 10 1520, where we give you like 17, we want to tell us that 17 cannot be five cannot be divided by 70, something like that.

So we're just gonna automatically get an input First of all, and make sure it's an integer.

So we'll say inputs a number.

And then we'll see if there's just a gay, what wants to see now is that if the value so what this is doing is add value is basically the number the user input.

And then this percentage sign means the remainder.

So we'll say if the user input 20, so 20 divided by five is four, then the remainder is zero.

So when we do something like 2025 in Python, it means give us the remainder.

So first of all, let me just cut this out.

And let me show you what that does.

So if I say print 20 percentage five, now you're gonna see that it's going to print zero is going to print the remainder of that division.

When I say print 22, it should print me true, because 22 divided by five is four, then the remainder should be too noisy, right? Do we have to do them just quickly bring that back.

Right now we're saying if the value percentage five, that means if the remainder is equals to zero, then obviously, that just means that value can be divided by five else value can not be divided by five.

So since we're using an integer, let's add a comma here, like this.

So this should work.

Now it gives us a number, let's say Andrea now says Andrea it can be divided by five.

Let's run this again and give it a number that can't be divided by five like 106.

He says 100 and sees cannot be divided by five.

So that's how to build a Basie program with Jack's even number can be divided by five.

Now the last exercise, which we're going to do on FL statement is going to be the exercise to check if the length of a sentence is less than 10.

So again, we're going to collect a value, but this time, it shouldn't be as drink, because it's going to be a sentence.

Now, once a cake if the the length of that sentence is less than 10.

So if the length of the sentence is less than 10, they will say value is less than 10.

Else Z value is greater is more than j.

So gases lead to this list typing random things like my name is my name.

Now this is obviously more than 10.

I eat enter, he said not supported between instance.

So because this is not seen as a as an integer, we can do this.

So right now, anytime we are using this less than or equals to, it has to be as does basically be an integer, we can do less than or equals to four string.

What are some other ways we can do this, we're going to talk about seats.

We could have solved this now.

But I'm leaving this to for the tutorial, because I don't want to jump in some steps.

So for any tutorial, we're going to come back to this exercise and I'm going to show you how to do this with strings.

But for now I will be get the concept of use an else statement.

So before we continue with more concepts in Python, we just want to do a simple Python program with Jack's even number is an even number or an odd number.

So as we know an even number is a numbers we can be divided by two, an odd number is the one which count.

So this shouldn't take us up to like two minutes to do.

So I'm just going to call it an input from the user and name is number we'll say input will say and a number and then want to make sure that these is an integer.

And then we're going to say if number percentage two is equals to zero, then obviously, this is an even number.

So what this is doing is that if the remainder of number divided by two is equal to zero, then is an even number.

Else.

We just see, odd number.

Now when we run this, we put the value of licence to cease.

Now since this is an even number, we run it again on the booster to 767 is an odd number.

So does also do a simple exercise.

sighs like that using if statements in Python.

In this tutorial, we're going to be talking about dictionaries in Python.

So dictionaries are used to store data values in the key value pairs.

So dictionaries also data type, just like least just like strings.

dictionary is also a data type.

But this dictionary stores value in a pair of keys and value.

So just like a main dictionary, like an English dictionary, where we have the word as the key, and the value as the meaning of that word, so that's basically our dictionary works.

Now dictionary, D are changeable, which means you can modify them even after like configuring assigning them.

But they don't allow duplicate, not liking lists are tuples, that you can type in a value more than once in dictionary, you can do that.

So let me show you how to write a dictionary in Python.

So let me just name this dictionary, my gait, how to write a dictionary, we're gonna use these curly braces, and then we're gonna give you the key.

So the key might be something like, name, and then I'm gonna use this column.

And then the value can be same.

And then I'm going to put the comma, I can have another key and value in, let's say, age.

Unknown, let me say something like nationality.

I can see something like African or something like that.

And then let's just have these two.

Let me give it one more.

I'll see qualification.

Let's see college degree or something like that.

So this is a basic dictionary in Python.

Now, let's just start with the basic thing by just printing this dictionary to our screen was this.

Let's just print my dict.

Now once we print this, you see that it just gives us the dictionary name theme as now the African qualification college.

But now let's say we just want to print only this name, value, what to print the value of this name.

So this is the value and this is the key assigned to this value.

That means if we want to get this value, we need to search for this key.

Just like when you go online, and search for meaning of order, meaning of anything, out of words, meaning of anything.

So play, for example, meaning of order, so order is the key, then the value you are looking for is the definition.

So does our dictionary work is very similar to the normal word dictionary.

So now once you get the value of this name, we can just use the square brackets after these n in the same name.

So what this is going to print for us is team right here you can see team, which is the value of this name.

Now there are other things we can do, as I said, duplicates are not allowed in, in in dictionary.

So now let's say I have two names.

And the other one is john.

Now when I tried to print these, you see his prints only the first one, it doesn't say I mean prints only the second one does the most recent one, it's automatically because this one out of it now does what I mean by duplicate not allowed in dictionaries, you can't have two t with the same name, we can have two values with the same name.

Now what I mean by that is this is the key This is the value.

So two keys, we can add them with the same name book I have two values.

Let's say this is named two.

unnamed two can still be the same.

Now if I print these, you will see that name is same name two is the theme.

So we got out the values the same we can repeat that.

But the key being assigned cannot be repeated.

It cannot be a duplicate.

Now let's say we want to get the length of this And it is very easy to get just seen Len.

Like this, then once we print you see tells us for that because we have four keys and values in here.

And then we also mix data types.

Now you know that let me just remove this, do you know that this name, the value been assigned to it is a strange devalue, besides the nationality is also a string, and the value been assigned to qualification is also a string.

But we can change it, let's say want to add like age, and we know that age will obviously be an integer, we can just add it here, let's say it's a seven.

Now normally, we will write an integer without the quotes that are going to write it in there.

And then once we print, we can still go ahead and print.

Ah, it's gonna print into cell phones with no problem.

can see it right here at seven, we can also add a Boolean, we can say is tall.

So it still can be true.

And then once we print age, I mean wants to print my dictionary.

So you see it's print true.

So it tells us that okay, this person is talk.

So we can add different data types.

And then what is very cool is that we can also add a list, so we can list of his friends.

So can the data type as a list like this, so we can see, one of his friend is Peter.

We can say Paul, we can see precious and odd, so lightyear wants to print friends.

Just gonna print those at least.

Okay, right here, it says invalid syntax error.

And that will because we forgot to add a comma right here.

So we should make sure to add a comma before adding another value.

So once we click enter, you see it gives us Peter Paul, and precious.

So now let's just bring the whole dictionary without anything attached.

Now we go down here, we see that it prints everything named team on everything we need to know about that dictionary.

And then, to check if this is a dictionary, we can also use the type.

So also, just put type here is going to print dictionary for us.

So you can see right, yes, this class is dict, which means that these is a dictionary.

So we can also make it more fun.

By specifying a variable, let's say we have a variable named x.

And we want this variable to be equals to one of the values of this.

So we can just simply say, X can simply be equals to mod.

My D.

Name.

So x now is name.

Now once you print x, obviously it prints the name.

Now, those are busy dictionary functions and dictionary methods.

So I hope you get the concept of dictionary in Python.

This tutorial, we're going to be talking about why loop in Python.

So while loop is a Python feature, which allows you to loop through a block of code, while a certain condition is true.

So let's say you have a condition like if a number is greater than 10, then it should just loop through a bunch of code below.

So just like a function with an if statement or something like that.

So we are giving it a condition that under age, we have a bunch of code which we want to loop through.

So let me just show you how to use while loop in Python.

So first of all, we can specify a variable named I can say is equals to one.

And now to use a while loop we can say a while.

One is still legs down six.

So this is a condition we're saying as long as one is less than six.

Then we just want to print I I mean as long as i is less than six, not one is this very good.

That is still one that we want to print, I and then we just want to increment i by one So we can see i equals two, i plus one.

So this is just gonna run this while loop, as long as one is i is less than six, it's just gonna print it to the screen, and then it's gonna increase it by one, then run it again, run it again, until it makes sure that it doesn't pass six, it doesn't reach six.

So you can also increment these by typing, i plus equals one, the same thing, anyone will walk.

Now when we run this, you see now it is 12345.

So what happened was that is loops through this block of code.

So we said while i is less than six, so that means it should move to this block of code the printed I, then after that we incremented it, there, now i is equals to two is still less than six.

That's why we have to, then it did the same thing.

incremented it we have 345.

But after five, it did the same thing.

incremented by one, but now i is equal to six.

So because that's this condition is really false, is no more less now seeks then the wild loop to stop, you just like caught in a way from that wild loop.

So that's basically what while loop is about, it's very important in Python, there are a lot of Python programs, you want to build that we needed to use a while loop to loop through different things with a condition.

And then you can also do more things like e while i is less than six, or i is equals to six, something like this.

So now you know that when we run these, it should print those 126.

Because there's no more just only when y is less than c so so when is equals to C.

So now it gives us an error, because when writing equals two in Python, it has to be double.

So let's run it again.

So now you see 123456.

So why loop in Python loops through a block of code at a certain condition being true.

So because this is true, one of these is true.

It just prints I increase it by six comes back does looping does that code again, increase it by six come back, and then it makes sure that it goes to six.

Now go.

So say i equals to 10.

Once I run this, it gives us 12345.

So if we say and and now we run it, it doesn't give us anything.

So sometimes a wide loop.

I put this in why loop conditions is not similar to if statement, you know, when you state where we can do Eva is less than six and is this, then you should do a certain thing.

So now you can see that if i is less than six, and i is equals to 10.

So the reason why this didn't run is because at first i is less than six.

So that's you drawn, but we'll say and it's mostly equals to 10.

But we know that i right here is not equals to 10.

So if I change this to 10.

It still won't run.

And the reason why it won't run is because one of these is not correct.

So I is not less than six because 10 is no less is what we say is less than 16.

Now, then we can run it, I guess see it's print something now.

So why is he and all in the condition? Where is he Oh, as long as one of it is one of the condition is true, then that while loop we run both way.

And the two conditions must be true before that, why do cross so now they just don't bother about the and and now let's change to one less changes to 10.

So now when we run this we should get 129 let me just expand this we see that we have 123456789 now this is basically the basic concept of why loop in Python.

In this tutorial we're gonna be talking about for loops in Python.

So follow disease for iterating over a sequence.

Now this means is used looping over a sequence.

And this sequence can either be at least a tupple, or dictionary, even a string, a range of numbers, it can be anything that is a list.

Now we use for loop to loop through them.

Now a for loop is very used in Python is used a lot in Python, actually, because most of the times we have lists of data we have data, large amount of data now for loop is used, again for loop to loop through each amount of data each value in that data.

So let me just show you how we do a for loop, or we call the for loop in Python is very easy.

Now for you to type a for loop, the first thing you need to do is to type this for keyword, fo R.

Now this keyword shows that we want to loop through something.

So we can see four letter in four letter for letter in.

Let's say something like, hello.

Now this is a for each letter in ello, which is h e l l, we just want to print a letter.

Now when I run these, you will see the experience he differently, it brings everything separately.

So it's looping through each letter in that ello string, like iterating through the sequence.

Now we can also do these by having a list.

Now you can see my lists, I would get up this list to be anything ledger, C, gi j Yu Gi Oh, now we can look through these and say for, let's say like for x.

Now not that this can be anything, let me just this in which I put later it can be denoted by anything.

It can be represented by anything.

So when I first got started with Python, I was kind of confused in this for loops, just simply because of this letter.

So I thought that you know, we're since we're using a low, and each is called kereta.

Ages got a letter is got a letter, so I thought we have to use later for each.

But now I just want to clarify that so that nobody will have to go to that confusion.

So this can be denoted by anything.

If I say four eggs in a row, and I just say print x is going to do exactly the same thing.

If I say for gi or for anything I do, it can be denoted by any single thing.

Now let me just so now I just want to say four items, or four values will be better for values in this my least.

So I'm going to remove this string as in my list.

Now I just want to print both values.

Now once I press run, you see nice prints everything j ij Yuju, which is gi JU and J.

So that is basically how to just loop through a list.

Now you can look through anything, actually, you can look through a dictionary, so they just have a simple dictionary.

And then let's say we have curly braces, and then we have name.

JOHN, we have age the thing that I just leave those two.

Now you can see four values in my date, print values.

Now as I bring these you see it says name, age.

So you just basically sprint, these two which we have name and age.

So that's iterating over words over a list of values.

And then in for loop.

There's also something we call the break.

So now let's go back to our list.

Just Yeah, so now we are we still have this or at least I would say four values in my list print values, but I cannot see if values is equals to Jeju then I want you to break.

So what this is going to do is that it's going to look Do it one by one, it goes from j i, then he goes to J au.

So I've seen, once it gets to this j, you It should break, then you should stop that loop.

So once I run these, you're gonna see, okay, right here is supposed to be double.

Once I run these, you're gonna see Justin j, i and j U.

Now, why is this, I said that it should continue looping brings all the values, but once it gets into that value is equals to j, u, m is once in a loop to this j, you then break, break me stop the loop.

So that's why I want to get to J, you it stops, does Oh, we don't have j Oh, right here.

Now, we can also, instead of having the break here, I can do something like this.

So even before printing values, I can have my if statement.

And I can say, for value in values, if value is equals to j, u, I can say break.

And after that break, I can print values.

So if you haven't gotten by now, the difference is that if value is value, so is looping to these values.

But if the value is value, it should break.

You know, in the last time, it first printed value, if as Peter is Jay, you before it's broke.

But now, if value is J, you should break before even printing.

So it's gonna guess that Okay, we have j you want to break, then we're going to print so Python runs code line by line first runs this code and runs this then runs this, then like that.

So the first thing he sees is that we are checking if what want to look to next is j U.

And we see that yes, it's true is j U.

Now we just break, then after breaking, we print values, so the only value I want to print is G because we're broken when we go to you.

So when I run these, you see that I only have gi we don't Prince j au again.

So that's basically how to use the break in for loop.

But we can also loop through a range of numbers.

So let's say we have 4x in range.

For now, what I can just do is to print x.

Now once I print x is going to give me a list of number from zero to three.

So it's gonna give me a range of numbers starting from zero to the non last number before four.

So I also change is only like 10, you're gonna give me from zero to nine.

So as you can see, it gives me from zero to nine.

And then we can also specify for each to loop through a particular range of number.

So now we're given 2010.

But we can say each loop for each loop from three to seven, or from 10 to 70, or any amount.

So if we wanted to loop from three to seven, is our going to do it, we just say for x in range three to seven, look to this number.

So when I run these, you see it gives me 3456, it doesn't start from zero.

So it looks from three all the way to this seven.

And that's how to loop through a particular range of number.

And the final thing I'm going to show you in for loop is that we can also use the else statement.

So now let's just loop to for a range of seven.

So after looping, we can see else, what this else does is that once this loop is done, once it's finished, we can just print finished looping.

So now once I run this sprint from zero to CS, and it says finished looping, so that's what the the else statement does, is that it just simply, first of all finish the loop first of all finished iterating over the sequence, then it just tell us whatever is in the L statement.

So that is an introduction to for loops in Python.

In this part, we're gonna be talking about 2d lists in Python.

So to do lists also mean two dimensional list.

So it's like well, we have multiple lists inside a list variable.

So right now we can have a normal list like my list which can Just a numbers like 1234 I was reprints my list, know that we're gonna get 1234, which is a normal list.

But now we want to have a to do list, first of all is recommended to press Enter just to organizing the rotation, then we're gonna have a list.

So this can be 123.

And then we can have another line, which can be 456, then we are they've come up on another line can be 789.

So now this is a to do list, because it has rows and column.

This is obviously a list in a list.

So dislike the high level list and his like his sub sections or something like that.

So now once we just print my list, you'll see that I just give us this normal list.

But let's say we want to get this value of one or two.

So we're gonna get it using the index number.

So we know that the index number of this is one of zero, which is the first one, then we also want to get the face value, which would be zero.

So once we print this out, you will see that we have one.

But let's say we want to get the value of five.

So we know that the index number of this is one that was indexed number five, it's also one.

Now once I run these, you see now that I have five.

So that's basically navigate on like brains, or get some certain values from your 2d lists.

And then we can also look through these.

So I'll introduce you guys to nested loops.

So nested loops is where you have a loop in a loop a for loop to be specific when you have a for loop in a for loop.

So now, instead of just printing, let's just say for something like lists in my list, they initially just print my lists.

Now as I run these, you see just print my list, have one list in my list, it just loops through that.

One, instead of just looping through this or just printing this, or I can do is I can add another for looping the so for least in my list, and I cannot see for maybe the rule or the column for row in lists.

Then now we want to print row.

So when I run these, it gives us an arrow does because in Python must have indentation to show that this is on the DCE.

Let's run it again.

Now you see it says type object is not iterable.

So for row in lists, must make sure that everything is intact.

So I put the list, but the name of this is lists.

So after that is now when I run this again, you see it gives me let me just open this up.

You see it gives me from one to nine, which is every single thing via 1234 all the way to nine.

So that is how a nested loops work.

So is like looping through a loop already.

So a loop in a loop.

But I have not tried it before.

But I think we can also have another loop again on looping through something like Yeah, yeah.

So there are various things you can try out with Python is very great.

So I hope you understand the basic concepts of Sudhi least are nested loops.

So in this part of the tutorial, we're going to be talking about comments in Python.

So comments is being used to prevent a particular code or block of code from running with your actual program.

Now let's see we have print.

Hello.

And then we also have print one.

Now when I run these, you're going to see brings a low one.

Now if I call me and I put an ash tag, right beside D Like this, you see that this is grayed out is no more part of our code, it's still there.

But when I run, it is not going to be wrong with our code, the only one prints.

So that's what comment is for, mainly in Python comments is are mainly programming in general, is useful, explaining our code or is useful, taking down notes in our code very well, like making our code more readable.

In Python, you can also just add comment, let's say you just want to quickly test your code without a particular code block, you can also use comments.

So you can also add comment at the end.

Like you can see ashtag this line prints Hello.

So you can just use it to explain your code.

Or you can just use it to block the code from running.

And as you seen, if you're two comments more than one line, you can put hashtag on this line on the second line, then everything will be commented out.

But there's also a better way to do this in Python, you can just easily add the let's say you have a code block, or you have a function like my phone, Shawn.

And then this function just prints.

Hi, now let's say you just want to comment out this particular function.

Now what you're going to do is above of the function, you're going to add three quotation marks like this.

And as you can see, it automatically commits all your code out.

So if we run these now, nothing's gonna run at all.

It's, it says we have a syntax error and stuff like that.

So we have to close these comments by putting those three codes back on there, we'll want to close it, so want to close on the beginning of this function to the end.

Now when we run these, we will see that print ello and print one run.

So now we try to execute these by seeing my on scarf.

You see, that's gonna give us an error.

It says name error is not defined, now means it doesn't even see this part of the code will define the function when we try to run it, it doesn't work.

So that's what comments are used for in Python, mainly two things useful removing your code, or judges or taking notes or making your code more readable.

In this tutorial, we're going to be building a basic calculator using Python.

So we're going to be using all the skills and everything we've learnt in the previous sessions are going to be adding them together and then building a simple calculator.

So now what wants to do is to have three inputs collect three inputs from a user, which is the first number, the second number on the operator.

So the calculator want to do this very basic is just the one that is going to add, subtract, divide, multiply two numbers together.

So want to collect a number, which would be number one, and the second number, which would be number two, and the operator, the operator is whether you want to add or subtract, or whatever you want to do.

So now let's define that to say no one should be equals to input.

We can say enter first number.

And then we'll also do the same thing.

I'll say num, two inputs and second number.

And then let's see Opie, which is the operator inputs, and, operator.

So now that we have the three inputs, when I went to use an if statement, so what's going to happen is if the op, which is your operator, is equal to addition.

Now we just want to basically add the first number and the second number, then we're going to use an Elif to get his sub subtraction, whatever, then we're going to do, according to the operator, the users input.

So let's say if op is equals to plus.

Then is equals to close by just going to print out number one plus number two So now let's just test that.

So right here, let me say two, three.

And I want to add nice, he says 23, which is very wrong, two plus three is supposed to be five.

Now the reason why it says 23 is because he still sees this as a string.

If I over need to see it says drink, what is meant to see it as an integer.

So because it's a string, he's just concatenating it together, but we want it to be an integer, so it can perform the normal operation.

So we have to say, ain't no ain't gonna pay stub bugs are gonna do the same thing for the second one in a beast.

Now, when we run these, it should work.

And our first number, let me say 75.

Our second one should be 25.

I want to add nice, it gives me 100.

It adds it up together, that is what we want to happen.

So let's just do some gestures.

Or let's say the addition is no one plus not two.

But now want to check what if a user inputs subtraction, so if a user say subtract, then we just want to print this subtraction is number one, minus number two, bow must make sure to disclose sigh right here was your no we can do these we can do the audition is no more close no to because this is a stream, this is a number.

And then this is a string.

So what we can do right now is to just put a comma, right here, so we can just cover.

So let's test it out.

If I see 17 and 20, I'll just subtract it gives me the subtraction is 50, which is nice.

And then let's do the same thing for multiplication.

So we just say the multiplication is number one, times number two.

So that's the basic arithmetic for multiplication.

And then we're also going to do exactly the same thing for division.

So if it's equals to divide, then we just print out the division is no more one divided by num, two.

So now this should work.

Now when I run it, and I say 6020, and I want to divide, you see, gives me the division is 3.0.

What if I do something like the absolutes of these? Oh, no.

So absolutes of these, let me run it again.

Now if I say 60 and 20.

I put divide.

Okay, so you gave me three points.

You I was expecting you to give me three.

But we're going to bypass that.

So this is how to build a basic calculator using Python using getting user inputs and then using if statement.

If statement Elif statement.

So let's add one more thing.

So if the user doesn't input plus, minus times, or divide, what we want to just tell the user that will be on iOS was in print, and can just say, invalid, operator.

So let's test this out by running it.

As a user says sisty.

All 90 this time on seven, and you're gonna do something like dollar sign.

It says invalid operator.

But now let's run it again and test from beginning.

So let's test for the addition nighty 20.

Paddy showed us me one 110.

Now let's test for this subtraction.

We are 50 we have 70 So pratiques, it gives me minus 20, which is the correct answer analysis for the multiplication 40, we have four.

And then we have multiplication.

Now it says wants to see, which is correct.

And therefore the division also, we have 80, we have five, we have division, sustain point zero, now everything is working fine.

So I hope you understood what we did by building this basic calculator.

In this tutorial, we're going to be talking about try accept in Python.

So what this does is that it prevents an error.

So most of the times we are working in Python, you're gonna get a lot of errors, you might do some things on the program is going to draw an arrow or an exception.

So most of the times this error just stops, our programmers cut our program, if our program is running during a specific task, once an arrow comes up, do program is down.

So to prevent this, we use the try accept method.

Now this is going to get automatically get an arrow, and then just print whatever we want to tell the user.

Now for example, you know, when we want to do an addition, we want the user to input an integer.

But let's say the user inputs a boolean value or string or something else.

So instead of the, but you know, Python telling train an assertion or train has an error, we can automatically tell the user that invalid input that this is not a string or something like that.

So let me show you how to do that in Python.

So now, let's say I have x is equals to inputs mfsa integer to be specific input, they will say, input an integer.

And then we print x.

Now when I run this was the inputs are integer, it print x, it prints seven, the interior.

Now let me run it again, and input a string.

Now you see that it gives me an arrow named value arrow, in Valley literal for int.

So it's saying h J, K is not an integer.

So we can just automatically get this arrow by ourself, and then, you know, tell the user instead of Python, train this exception, which can stop our program.

So for us to do these wants to do, we're going to say, try, like this, that oh, this is gonna be in try it after it, we're going to say, except, don't, we're just going to print value, not an integer.

So this dry is saying, try all this code, then if there is any exception at all, just print value, no an integer, or we can just print something with drunk because we don't know what's my cost.

The exception is might not be that user inputted a string, it might be something else.

So there's just say something went wrong.

Please try again.

So now when I run these, and I input theme, now you see it says something went wrong, please try again, it didn't roll this error, like the last time, so does how to basically use try except in Python, but it's more deep dandies, we can get, we can use the exit method for some specific type of exceptions.

If I scroll up here, you're gonna see that this exception it gave us is called value error.

Now we can say, except there is a value error, then say this.

This one I'm doing right here is just guessing if there is any error at all, but let's be specific.

Let's see if there is a value error.

So now, if there is a value arrow, a value error means the user inputted what we don't want to ask for a string and then input something else.

There was say there now we cannot say value.

Not a string, but not an integer.

Now when I run these Scroll down to something else.

Now it says value not an integer.

What is it getting for only this type of error? Now let me try to add another arrow intentionally.

So let me say, let me try to call cat needs with a name.

So right here, I'm trying to concatenate with a variable named name.

But we didn't have any variable like that before.

So it's going to give me a name error.

So when I run these, I would rank.

Now you see, like, if you scroll up, the shows me name arrow name is not defined.

So what if I just put only accept and I run shows me name is not defined.

So this is because we're trying to define something that is not like a variable that is not the so that arrow is from us, which you can pass something like this.

But now we're trying to pass an arrow from the user, we're trying to make sure that the user doesn't input anything wrong.

So now we say except value is not an integer.

So I hope you get the basic concept of try accept method in Python.

Now it also do something like this changes, but something went wrong.

Because see, something went wrong.

Now, when we say something went wrong, after this, we can say else.

Print, nothing went wrong.

Now what this else is doing is that after typing after running this code, if there's anything that went wrong, you should do this.

But if everything went fine, then you should say nothing went wrong.

Now let's run this is asked me for an integer, I want an integer.

Now it prints out the integer and he says nothing went wrong.

But if I run it, again, inputs A strange noise, it says something went wrong, but he didn't say this.

So this else is, if everything is successful, if there is no error, then he's gonna say something, nothing went wrong.

Then the last one I'm going to show you is called Finally, is also a key word.

Now this is going to run either there is an error or not.

So I can just say, try accept, finished.

So whether there is an error or not, this is going to print f seven, there is no arrow, it's print seven and says try is finished.

If I run it again, and I print a string, so it says something went wrong, which is these and it says try accept finish.

So that's just saying that after everything if there's a problem or not just print that try except finished.

Now I want to talk about reading files in Python.

So sometimes when coding with Python, you might want to work with some external files, let's say like a text document, or like, like a spreadsheet, like an Excel spreadsheet, or like an HTML file or any external file.

So he wants to know how to read and write that file.

So let's put that to practice.

First of all, let's create a new file right here.

And let's just name it something like it's been saved these and then I'm just gonna save it in the same place.

I saved these.

So let me see all files.

DSR, I'm sure is located here.

First of all, let's cancel this and make sure we know where this is saved.

Yeah, if I come here, yes.

So I see where it is saved.

Project john.

Good to right.

Yeah.

So now I can create a new file and then save it.

So right here, I can save it as something like countries.

t x t.

See, it's ready on the txt, I can just change it to all files.

So in this countries, I want to have just a list of random countries.

So I can say Ghana.

I can say Mexico.

I can say Morocco.

Let me say Spain.

I don't have any spelling errors there.

So Ghana, Mexico, Spain.

Yeah.

Think as Okay, give me one more see France.

So I think that's okay.

So now for us to read this file, we have to like import it into this our Python file.

So it's very easy to do, what we just need to do is to say open countries, which is the file name dot txt.

Now, we need to make sure that these countries are txt is in the same folder as this Abdo pure so we can easily navigate to it.

And then after saying this, the second parameter This is going to take is R.

Now what these are means is we want to read on this file.

So once we're only read this file, we don't want to edit anything on it.

Then there's also something like W.

Not w means want to write on this file, we want to edit this file.

And we also have our plus a, this a means what to append to the file, so we can add in the middle of the file or modify the file or make any changes, we just want to append to the ending of the file.

And then we have one more call our plus, this means we want to do both reading and writing.

So give us full capability.

So that's what the outflows is for.

But for this part, we're going to be working only with our so we're opening this file.

And most of the times, we always want to save it in a variable.

So let's just name a variable file, country file.

And then it should be equals to this.

So if we print and anytime that we open a very file, and then we open a file, we'll resolve to make sure that we close the file.

So down here, we can also say, country file, dot close.

So this is to make sure that our closing the file.

And then in between those, we can do anything you want with a file.

So now I can just simply print golf file.

So first of all, I want to check if this file is readable if I have access to read it.

So I'm just going to do is to say cow file dot readable.

Now this is just going to return a boolean value true or false.

So let me run this.

So now it says no such file in directory, countries dot txt.

So let's make sure.

So what we're going to do is to navigate into this folder, and make sure we create that.

So let's go there.

I think I have it in right here.

So this is in project.

Okay.

And then Django.

So I think I'll be right here.

And then there is countries dot txt, c o u n t ri is CE o u n t ri ES.

So it says that we can't open so it says no such file or directory.

So what we just need to do is to do something like this.

These, although this is not the reason why we're having this error.

So when we run this thing gives us that error.

So the best thing to do is to just take the main directory to dads and then paste it needs this slash like this.

So now let's try to run it again.

Now you see it says it gives us this error.

Now the reason for this error is this slash right here, so we're just going to change it to slash the forward slash right here also And then when we run it again, now you see it says true.

So the reason we add the arrow is because right here is always in a backward slash, but we are using in Python, it has to be in a forward slash.

So now we are successfully navigating to dat countries dot txt.

So when we say, print confer the redo, so we're asking is, do we have access to read this file, it says true.

So we don't have access, we can read it is going to tell us false or not that this is true, then I think we are good to go.

So now that we can read this file, what we just want to do is to bring something like we can see curl file dot read line.

Now when I say this red line is going to print the first line of this file, which is Ghana.

So once I print these, you see now that it's printing Ghana, and this is like a sequence.

So if I print this file, again, if I say print, and I see a cow file dot read line again, now what is it going to bring the second line, and knows that I didn't make any change the same code, but when I run it, it prints Ghana, unmusical, secondary, do this and just print, everything I have in the body most recommended way is to just say, Gulf print lines, now brings lines is going to print everything for you in a list, so it's going to print everything out, do lines of your vendor file, and then store it in a list.

And now we can just get let's say the first one, I say wants to get the first one.

Now we are willing Ghana gang kids.

Last one.

Now you see we are France.

So that's how to use the realize function.

And then we can also making more cool by looping through this.

So we can see for, again, changes to a for loop for fells in curve dot read lines, like this, then we want to print we just basically want to print files.

So now, when I run it, you see just basically print all the old lines in which I have.

So the best way to call this is lines not Hell's so lines.

So when I run it again, same thing, it just print all the lines if I was a commie and make some change, like say Ghana is a country a free on the nice CV.

As I run it, that changes automatically made by move up.

You see right here, the first line says Ghana is a country in Africa.

So I'll be getting the concept of reading files in Python.

These are you can read files read by lines, really by text and stuff like that.

Now let's move straight to the next part of this tutorial.

In this part, we're going to be talking about writing files in Python.

So in the last part, we talked about opening or reading by reading files, reading external files in Python, but in this part, we're going to be talking about appending.

This is some text to the file, or those writing the old file again.

So first, to write a file, right here, we need to change this R to W.

So now when we change this out to W, let's just remove these as then we can just say golf dots, right.

And then what you want to do is to just write the ofa.

Now you can see that this is the file, but if I input something, you know, like, this is the new text.

Now when I run this, you'll see that nothing happens with that coming year, you see that it has been changed.

Everything I was there was gone.

So we wrote the whole file again.

Now this might be useful.

Let's say you want to write a new file.

It's very useful.

So the The reason why it ruins everything, again was because it was an existing file.

So it overrode like a router need.

But this is mainly used for creating a new file.

So let's say we want to have country now.

Now let me say, this is the new country.

Now once I save it, and run, if I call into this directory right here in my command.

So I'm going to do C, D, enter the directory.

Okay, it doesn't go to that directory.

But what this does is that it's created.

It's great this new file called country dot txt in that directory, so let's go there normally.

So right here, you see that we have a new file called country, let's change it and just say new file.

Now when I run it, let's remove this space.

When I run it, you see nothing happens, we're right here, new file is created.

Now, that was all to create a new file and automatically write something inside it.

So let's just Ctrl Z back to the countries we were using.

So now, I have this country's file, let's say I want to append something to the bottom like a new text, what I can just do is something like, well, to append, I must make sure I changes w two a.

And then right here, what I'm just gonna do is you just say, file dot right, then this is a new line.

Now when I run these knots in opposing determinar, or when I come here is a pen, this is a new line to eat.

But you can see it joins it together.

Now let's see how to form a new line I want this to be aligned to I can just come here.

And I can see backslash n.

Now these are magically going to take you to a new line, when I run it, again, are kamiah, you should now know that this is on a new line.

So that is basically how to append in Python.

Now you can do this for various types of videos file extension.

As you know, we did this for the text document, which is dot txt, you can even use a Python file to open a new Python file.

Now let's put that in action.

Now let's say want to open a new file and name it new dot p y.

And then in that new dot p y i want to write and they weren't allowed to write in it.

So right here Now, let me just crude, these, I can just easily write a Python code, I can say print.

This is a new file.

So right here, I just wrote a simple Python code.

And then obviously, we have to use the backslash before we can write a code.

So right here, I use this print, this is a new file, and it's gonna be in this new dots pure.

So now when I run these, you'll see now that we have a new.py file.

And then I can just when I come here, I can run new dot p y, you see now that it just simply prints out this is a new file, which was the command or the line we put in yet.

So it is also very important and very useful writing the new files in Python.

Now we're going to be talking about classes and objects in Python.

So I must say that Python is an object oriented programming language.

So this means that anything that deals with classes, objects, and things like that, were classified as object oriented.

So classes is just like a feature in Python, say something like a function.

A function is a feature that Python as their classes is also a feature that Python book classes now is like a constructor of objects.

So you might not understand what I'm saying now, but when I show you the code, I'm sure you get it more easily.

So a class is like a construct of different objects on the class, we have various objects.

So let's just go ahead and show how to do a class.

So now I want to go to class, we're just going to say class using the class keyword, then we can say, my class.

Or then on the year, we can see x equals to five.

Now we have this class.

This is the class, the name of the class is my class.

And then we have a x, which is an object on that this my class on x equals to five.

Now want to create an object, this is actually a value, or I can say an attribute on the class.

Now, let's say we want to create an object using this class, we're just going to do is to do something like p one, something like that.

It goes to my class.

Though we initialize it, there will gossip print be one dot x.

Now this is going to print five, because we're saying that P one is equals to my class, which is this class, then we'll just say print p one dot x, once I run this, it brings five.

So that's how to basically print dude that now let's talk about the init function.

the oddest thing I just said, Now, those are the basic concepts of class where we can basically use them in real life lesson you reward things and reward projects.

But the init function allows us to initialize different values in our class.

Now, for example, we have this class, let's say this class is named person.

And then on the other class, we're gonna have a function.

Gonna take two underscores in it like that, then you're gonna have some parameters self.

Now this stuff is gonna be there is just there.

That's the way it is.

And then let's say it does name, which we are going to put our, let's say, as age.

And then.

So we put our colon just like a normal function.

So let's remove these.

And then to determine the name of this self, dot name, can be equals to name.

And there we go, oh my god.

And then we're gonna do the same thing for the age.

So that age is equals to age, just like that.

And then let's just initialize it the way we did here.

So P one equals to my equals to person this time around.

But now we have to give it this name, and this age.

So we'll say the name, we can say the name is john.

And then the age is 87.

Now once we print p, one does name.

You'll see that it gives us, john.

Okay, so now it says indentation error.

So this is under this function supposed to be indented.

So let's run that again.

Now you see that it's printed john, we can also print B one dot h.

And they want to see that it prints at seven.

Now also make this allow user to input.

So we can say name is equals to input alkazi, enter your name.

And then we can say age is equals to input a, which you can say, and your age.

And then once we have the name and age of the user stored, we can just replace it with these as a name.

I say Ah, now when we run these, first of all, it asks us for a name, but I said team, it's the NIH, NIH just prints team at night.

So we can also use a class to do something like that.

So classes are very broad in Python, and it is very, very used in Python.

But there are still some other objects properties that we can do that let's say we want to delete a property from these icons or delete this age.

So let's just remove these and then let's give it the 10 Join.

Now, let's say wants to delete his age from it, what we can just do is to just say, dl p one dot h.

Now, once we delete p one dot age, this is not going to have this age in it again.

And then we can just even delete these objects in total by just saying delete p one, once we run this, this is gonna be deleted.

If we try to print p one after that, it won't work.

Now, he says, Your name not defined that because we've already deleted p one, there is nothing like that.

So we can print what is not.

And then we also have one feature we can use in the class.

So right here, let's say we have a class that is named person.

And for now, we don't know what to put there.

We don't know the values, and we just want to continue coding.

Okay, so to encode pass, so this pass allows us to bypass any error.

So if we have like, this class that is empty, we can just put pass for now they come back, like add attribute.

So it was I put pass, and I run, this could not innopolis.

But if I just only put class person and I run you see is gonna give me an arrow.

So this passage just to bypass the arrow, so we can continue with our code for the main.

Wow.

So I hope you get the concept of class and objects in Python.

Now we're gonna be talking about inheritance in Python.

So Narita simply means taking from an existing class, and then getting all the metals and everything in there and putting it in a new class.

So you're gonna understand what I mean in a bit.

So let's say we have an existing class in this file name new dot p y, I just created this file we actually created earlier in this video, let's have a class name, student.

And then let's say that name is equals to same age is equals to 34.

And LSA gender is equals to mu.

Now we have this class here, we can easily import it by saying count can see from new.py import student, which is this right here.

So now we are importing student.

So instead of saying from noodle spy, we can just say from New without adding p y, the extension, it automatically gets that we are importing from this file.

But before we got impulse, we need to make sure that this new up I in the same directory.

So let me just cancel this, we need to make sure the same directory.

So now I have this new class named person, what I just want to do is to just see this student.

So I'm getting everything from this to dance class, which we narrated, I'm just putting in this space in clubs.

So I just put pass to avoid any error.

Now I can say p one is equals to person.

And I can now say p one dot name, I can just said print.

b1 does name.

Now once I run this, you see it prints theme, all the way from New Wi Fi.

bunchgrass is running up.pi.

So that is the basic concept of inheritance in Python.

It inherits every single thing which we have in this class.

And it does bring gates right in this class.

So it's like a duplicate of that class was not a duplicate because different names in different file.

So it's called inheritance in Python.

In this tutorial, I'm going to be talking to you about the Python interpreter or the Python shell.

So the Python shell is an application that is automatically installed whenever you install Python on your computer.

So let me just quickly open up my python shell.

So this is my python shell right here.

As you can see, Id issue So let me show you how I opened this up, you can just come here and just search for ID l II.

If you have Python installed issue automatically bring that out and just eat open.

But since I already have this open, so the Python shell is just like a smaller environment where I can run on quickly test some Python code.

Like everything we've learnt in this tutorial, I can easily code them yeah, like, let me say, print you enjoying this tutorial.

Once I press enter, you see it prints that immediately, it automatically runs that code.

As I press Enter.

And we can also says like a very, we're gonna say name is equals to theme.

And then we can now print name.

variety in the Python interpreter, we can also print the name without even writing print.

If you just say name, it automatically prints it out.

Well, that's only when you're just testing your code yet in your Python shell, you can do that in your main editor.

Now we can do a lot of things like I'm sure we can use a for loop.

Let me say for letter in same Yeah, like that.

Then I can just see print later.

Now you see it's automatically prints team, I can do anything in year I can even write a class.

And I can see the class in the person.

And then I can see name is equals to john.

And then right here I can say p one is equals to person.

And then I can say p one dot name.

This is just gonna print me john.

I can basically do everything I do in the code editor right here.

I can have an if statement.

Let me say if b wonders name is equals to john, then print Yes, it is.

So now he's gonna print Yes, it is because pianos name is obviously equals to john.

And then we also perform our basic arithmetic, like two plus three gives us five, nine minus zero gives us nine.

And everything which we can do on the normal place.

Because we'll define a function, let's say we have a function to say, I and then let it pass a name.

I let the name be unnamed.

Under let's say print.

I name now let's see I give it john.

Now you see it says I joined.

So almost everything which we can do in year, we can also do it in our main editor is this like the same thing but is not advisable to use these when building normal projects or stuff like that.

This is just basically for testing or anything like that.

So let's also try more things like try accept.

So try, let's say age should be equals to any of the inputs of enter age under this glues that so I wanted us to be age and then we just say exit Yeah, we must make sure we have the right indentation.

So except it gives us an error because of the interpretation.

But we can basically do all these writing in our Python ideally is what I want to show you.

So sometimes you might run into this error of indentation syntax.

Because is the indentation is not really obviously clear.

Just like the way it is right here in Visual Studio code.

So that's why it's recommended to use your normal editor and not basically an ideally for editing, but often get the concept of a Python shell.

That's going to go above the Python interpreter.

So now we're going to be creating a simple signup and login system in Python.

So we're going to be putting in everything we've learned in this tutorial, and then building this simple program.

So as you can see here, it says, create your account.

Now it says the input username, I'm just going to input admin, and it says we should input password.

I'm going to input admin.

As the password now says user admin created successfully login now.

So what this program does is that it creates this user, obviously one or Jenny, we read database, we're just storing this in variable.

Once we run this program, again, we have to create again.

So it's just four practices.

So once we create an account, and he says use our greatest This is really, it says login now.

Now when we try to log in, if what we type is the same with these, then automatically will be logged in what is different if our username is wrong or password is wrong, then you just say invalid credentials.

Now let me try to log in with normal.

And I say admin now says user logged in successfully.

Let me run this again.

Let me let me now create another one admin, again, admin.

Now it says admin created and wants me to login.

If I now say admin, by the password, and I add to n, I click enter.

You see now it says invalid credentials.

So this Python program we're going to build is gonna get whether the password is right, or the username is right or not.

So let's go straight into that.

So let's just quit these come back here.

We can also quit this.

So what's one to do? We're going to take in four parameters.

So the first one is going to be the user name and the password for creating accounts.

And the second and the third, and fourth is going to be user name and password for login.

So let's do that.

Let's say user name will be equals to so this is the first is our new for creating account.

Because to our inputs, I will say and user name.

And then for the password, say the same thing inputs into a password.

And there was users enter the username and password, we can just print to the user and simply say that your account has been created successfully.

And then now we know how to tell the user to login.

So let's print again, login now.

So now once you have another variable, which we use our name to, should be close to input and user name.

And then the password for the login.

password to input and password.

So now we know the Jq DS is equals to this.

So just simply say if user name is equals to user name two, and password is equal to password two.

So this is our if statement saying this and these must be equivalent.

That's why we use and if we use all is going to be wrong, because if the user name is correct, and the password is wrong, it's still going to look to us I so want to make sure the two are correct.

It took correct response before we log in.

So once it's correct, we can just say print logged in successfully.

But it was wrong else.

We just want to print invalid credentials like this.

So let's just come on to the top here and print something like that.

Create accounts now now this should work let's run it was just so we create a user name let's just say to me the password see me now your account has been created successfully log in now see me on the password see me now it says login successfully.

Let's run it again and try a wrong one others hai hai hai, hai hai hai.

Now when I say the user news, ah, ah, ah, ah, ah y.

But the puzzle is Ui Ui Ui.

Now, you see, it says invalid credentials.

So that's how to build that basic Python program using getting user input.

And if statement.

I hope you understood what we did here, if you did it, you cannot go back in like five minutes ago, and just watch from there, I'm sure you're going to get it.

In this tutorial, we're going to be talking about modules in Python.

So modules basically allows you to get the function class or everything present in another file, it allows you to implement it and use those same functions in your own file or project.

So modules is very, very versatile is very widely used in Python.

Everybody use modules.

So let's say I have this file named noodles py.

Now, I have a function named say I.

And then that say, I function, I just wanted to print.

I know, Bob is functioning here, I can import these, I'll just say imports new.

Now this new is starting as a module for this my file.

Now right here, I can just simply say, new, don't say I was I CDs, I run this file, you see that it automatically says, so does how to use modules in Python.

Now there are a lot of things we can do with modules.

And modules are very versatile.

So if you want to, like I wanted to use a function that says, instead of coding from scratch, there's possibility that someone out there already written that same function, or similar to what you want to do.

And rarely as he does a module or library, in mutual gain, get and implement.

So now modules are in just on your local laptop or your local PC like this, modules are hosted online.

So Python as something we call Pip, which I'm going to talk more about in the next video, the next part.

So all the modules are more hosted online.

Let's say you're looking for a module that wants you to just do a specific task.

And you know that yes, of course, someone else would have done this, then you can just go and search for that module, or search around research there, you're gonna see that module online.

In the next part, I'm going to show you how to implement peep and then install all those kind of modules on your computer.

So in this part, I'm going to be introducing you to something will go beep.

Now P is used for installing external modules from the web to your local PC.

Now, as I explained in the last video was modules, they basically allow you to get us function from another file of Amanda library.

So PIP allows you to install a module from the internet to your laptop.

Now, if we go online, and then we just search for something like Python modules, then we can just see, let's see.

Let's go to P ypi.

So there's a site called pure ipi.

Now, this is where all the Python modules almost all the Python modules are being boosted.

As you can see 200 and H 2000 project.

So he just basically saying 200,000 libraries or modules that are hosted on this site.

Now you can see that each one has different tasks they do.

Now see this module is for Spotify recommendation.

Let's say ah, let's say we want a module like, let's just go to the home page.

And let's see what we want.

So you can also see trending products.

As training modules, a lot of different things.

And then let's say, we want to let's go to browse development of framework.

Let's just click on this.

So now this is the name of a module.

Let me look for Swan the as a description.

So Django deep serializer.

Django is actually a web framework, which allows you to build websites using Python.

So this one is saying a Django deep serializer.

So that's what this particular module does.

So while doing studies on our computer, we just type pip install Django, deep serializer.

The way it is being said here, then how do we now where do we run this command, if you're on a Mac, just open your terminal, move your new windows, open your command prompt, and the Angelus basically the pip install Django, I think deep ip serializer.

Now, if this is the library or module you want to use, you can just run this command line, and then it's good to go I installed this module or this library on your local computer.

Now you can see it says down collecting Django, deep serializer, then downloading Django deep serializer 0.1.

Point three and all those.

So it's setting up all these.

Yeah, so you see it says successfully installed Django deep serializer.

Now I have this on my computer.

Now very sure that if I want to import this, I'm just gonna look for our say we got imported.

Those guys good.

Okay, they didn't mention that here because we are not running a Django project.

So you don't need to understand what I'm saying for now about Django.

But this is how to basically install a module or library using PIP on your computer that does what PIP is basically about the and this beep.

You don't need to listen download peep externally, once you install Python be automatically installs with it.

That's why Well, once you install your Python is good.

If they ask if you want to install our component is good holistic, yes.

And they just add Python to Python just tick everything.

So the oldest components will be installed when you want to use them later.

So PIP is automatically installed with Python.

So if I come here, we just say for Pip.

You see, he says, Let me say Python, let me be specific.

So PIP Python, is a package management system written in Python used to install and manage software packages.

So as I said, Pip is used for downloading, or in this case, installing packages.

So modules are Swick also called m packages.

So P is the manager is what downloads it and store it on your laptop or your computer.

So does the basic concept you need to crash about peep.

So guys, that's gonna be all for this tutorial.

I hope you learned something and enjoyed the video.

Welcome to the Django Crash Course.

The main purpose of this video is to introduce you to Django and show you all the concepts you need to start building your own project using Django.

In this tutorial, we're not going to be building any full project bow we're going to be doing is taking each Django concept step by step using it in a practical use case.

And then by the end of this video, you will know how to build your own projects using Django.

Now, this tutorial is mainly focused for beginners, because we're going to be starting from the basics to the more complex stuff in Django.

So a quick introduction to Django.

Django is a Python web framework.

This means that using Python, we can build web applications with Django.

So without wasting any time, let's get straight into this video is a list of what we're going to be covering in this video.

So let's get straight into introduction and installation of Django.

Now, the first thing we need to do is to install and set Django up on our computer.

So I'm on a Windows as if you're on a Mac or you're on a Linux, the installation process is quite similar, just only some differences in the command line.

But I'm also going to see what you need to do if you're on a different OS from mine.

So this is just the job Go official site.

But now before you need to install Django before you can install Django, you need to have Python installed on your computer, because we're going to be using a Python package manager called Pip.

And that only comes when you have Python installed.

And Django is a Python framework, so why not.

So if you don't have Python installed, just go to Google.

And then it's very easy, you can just search Python download, and then just click on the first website.

Yeah, so you're gonna see the latest version, yeah, and you can just easily click on this to download it.

Now when you download it, you're just gonna install it like a normal application.

So I'm not going to do that, because I have that installed already on my own laptop.

So if you don't have this installed, just come here, download this, and then everything is going to be fine.

So now we can quit this tab.

So now we have Python installed on our computer.

What we just need to do next is to open up our command prompt.

Now these are command prompt zero are going to be doing most of the server running the installations and everything we need to do in our Django project.

So the first thing we want to do is to install Django, it's very easy, what we just need to type is pip install Django.

Now this command line is going to install Django on our computer, so it's going to install Django on the system, so we can access it from anywhere.

But I have Django installed already.

So what is going to tell me is requirement already satisfied.

If you work with Python very well, you know that once you have Python module, or library or package installed is going to tell you requirement already satisfied.

So as you can see, it says requirement already satisfied.

So I'm gonna do I'm just gonna close these, and then just keep it like that.

Now, you can see that we have Django installed on our computer.

And the version that is going to install is the latest version.

Now I'm not really sure if it's 3.2 or 3.1.

I know that won't Django three or so right now.

And that is what is going to install the latest version.

But let's say for a different project for each Django project, you want to have some particular packages just for only that project not for on your entire computer.

I also have a different Django version just for a specific reason on each project.

Now what we need to do is to create a virtual environments, virtual environment, I will see it's like a little box where everything your project is stored in.

So it's just like a mini environment where you can assess everything about your project.

So the Django version of that particular break is different, the whatever version you are using for any of that package installing can be different.

So it's just for that particular project is not going to be available in the old computer.

So for it to do that you need to first of all install a virtual environment on your computer.

Now the counselors my driver mate you can have, the one I use that I recommend is called Anaconda.

But that also has his installation process.

And that is mostly using Anaconda using machine learning because of the packages that comes with it.

But for this project, we're just gonna stick with a very simple virtual environment.

And this virtual environment is very easy.

We are just going to install it on our command line right here.

But it was Anaconda you have to download the application, just like we did for Python and then install.

So if you want to check that out, there are countless tutorial series on YouTube about it, you can check it out.

But let's just install a virtual environment right here on our command line interface.

And this virtual vironment is called Virtual env wrapper.

So to install it, we'll say beef install Virtua envy, rubber, and then after doing this put on iPhone, and then we'll say when and this command line is going to install it on our computer.

So again, I have this installed, so he's going to tell me requirement already satisfied, but for you, it should say should go ahead and install it.

So I'll just say show the loading bar downloading or something like that.

Now note that if you're on a Mac, when you are installing all these packages, you need to type PIP three.

So you can see that right here on the windows we type pip install, then we type the package name, but if you're on a Mac, you will type p3 install Then the package name.

So that's just the main difference within the windows and the Mac installation.

So now that we have these virtual environment rapa installed, let's now go ahead and create a virtual environment in Java Django project.

So first to do this, we're going to say MK, which is short form of MC, then virtual envy.

So now when we say MK virtual MV, we're gonna leave a space, and then we'll put the name of the virtual environment.

So you can give it any name, let's say you are working with a project named online dictionary, that's your Django project, you can also give the virtual environment name as online dictionary.

So just so that you can easily access it whenever you want.

You can give it any name you like.

But I just personally love giving it the name of my project.

But now, they just give it a name of my app.

So MK MV might help them get it Enter.

Now, this is gonna create a virtual environment named my app.

And then once it's done creating that particular virtual environment, what is going to do is automatically going to activate that environment.

So this will take a few seconds.

As you can see, we have this installed already.

And then before we installed it, besides the directory of where we are, we didn't see anything yet.

But after now you can see we have my app.

So this is showing you that it does is it has created the virtual environment called my hub, and it activated it.

So as I say, you remember I said that we were using a virtual environment, it is like a different box from the old computer.

But before we can assess that box before ourselves, our small environment, we need to activate it.

So now that we've activated this virtual environment, we can, anything we are doing in this particular command line is going to be in Dev and drive vironment.

So now, I'm going to install Django, I when I install Django by saying Pip, install Django knows that if you're on a Mac, you should be free install Django.

So now when I install Django and hit enter, is not going to tell me requirement already satisfied again.

And by now you should know the reason why that's because we have Django installed on our computer.

But we don't have it installed in this virtual environment, which is separate from what we have on our computer.

So as you can see, it is installing Django again, which is let's see if we have Yeah, installing three points two points to the latest version.

So that is the difference between your virtual environment and your normal computer environment or whatever you want to call it.

But as you can see right here, we add this environment as we created the virtual environment, it automatically activated.

So for you to know, if you've actually if you are in a virtual environment, or if the environment is activated, you are going to see these brackets and then the name of the environment in it before the directory.

So you know, when you first open your terminal or command line, the first thing you're gonna see is the directory where you are in a virtual environment, you will first see the name of the virtual environment in brackets, and then the directory that should show you that you are in Dev and driver match.

What if we close this command line, or we close this command prompt and come back, you know, we aren't going to see this my app again.

So I will now tap into that environment or we activate or enter the environment.

So I'm also going to talk about that in a few minutes.

So for now, you can see that we have Django installed in this environment.

That's very good.

Now, we're in a virtual environment for a while let's move straight to Django.

We have Django installed.

The next thing we want to do is to create a Django project because we want to work with Django.

Now Django has this command line, which allows you to create a project a new project.

So first of all, you need to make sure that you are in the directory you want.

Let me open my folder real quick.

So this is my folder.

This directory is what is in this command line.

So you can see right here, project slash Django tutorial.

By komiya.

You see down in projects Django tutorial.

So this command line is open is open in this direction.

So anything I'm creating, I'm creating a new Django project is going to be created in this directory.

Now, I'm just gonna say Django admin, start project.

And then let's give it a name of my app.

So yeah, my app is okay.

My project.

Let's just give him my project.

So you can see Now we are the virtual environment in my app.

And then this is the command line that we're gonna use to create a new Django project.

So once I hit Enter, and I'm just gonna give it a few seconds.

So you can see, it didn't show anything here.

But if I come back into this page, you see now that I have a new project named my project.

So let me come back real quick.

We did was Django admin start project my project.

Now, this is going to allow us to create a new project Django admin start project, then the name of the project after so if you're working on, let's say, an online search engine, or you want to name it, getting search, auto massage, or whatever you want to name it.

So you can say Django admin start project, then online search engine, or whatever you want to name your.

So that is how to create a simple Django project.

Now, if I press dir, I see that I have a new file, a new folder yet, let me opt into that folder, CD my projects.

So now I'm in my project folder.

If I press dir again, you can see I have money that was on my projects, I'm going to explain all these, they may look confusing at first, I'm going to explain all these I promise.

So I'm just going to quickly explain how you can also do all these things in Mark.

Now creating a new project is exactly the same thing.

Just like Django, I think admin start project my project exactly the same thing.

And then right here, when I press dir, what I did was to see all the files on folders in this particular directory.

So if you're on a Mac, what you need to type is LS.

Once you type l s, let me just quickly type it right here.

This so this if I click enter is not recognized because I'm on Windows but the only mark is going to show you a list just like this of all the files and folders you have in that directory.

And what I did was to go into that my project folder, exactly the same thing with Mark just type cd, my project you're going to go in.

So now we have this let's come back.

Let me go into this project.

What do we see here we see a file Monday money.py.

And then we see a folder, which is given the name of our project, which is my project.

Let me open it.

And we see like, a bunch of files here.

And I'm going to explain all of these.

But before I do that, let's bring this project into Visual Studio code.

So now, we have talked about doing everything in the command line interface, creating the project.

But what do we actually want to code.

So we need a to an ID, a code editor, whatever you want to call it.

And the one I love using is Visual Studio code.

So you might want to use auto me my own is pi charm in my own or use warehouse, why Sublime Text, but I use Visual Studio code, anyone you want to use is fine, as long as you know how to use it.

So now I have Visual Studio code here.

I'm just gonna say, Come here, click on file.

And then I'm going to open up a new folder.

I'm not Oh, yeah, I'm opening up a new folder.

So she'd been project Django tutorial, my projects.

So I want to open this folder, select folder.

should take a few seconds.

Good.

That's why I like Visual Studio code, because it's really quick and lightweight, compared to some other extent from other ID.

So this should open right now.

So give that a few seconds.

And, yeah, so as that is opening them quickly say something.

So it has opened right there.

But let me just close these.

So remember that I said, What if one of us says this particular virtual environments, let's say we close this command line interface, I want to assert this virtual environment.

I'm going to show you how to do that in our Visual Studio code.

So let's just come here.

So first of all, this is the files we get when we create a new Django project.

This money does py file, you don't want to touch it throughout your coding throughout when you're building anything you're building.

It is I personally, I there might be some developers will manipulate this fiber.

Normally, as a beginner, even as an intermediate Django developer, you don't want to touch this file, there's nothing you want to do here.

This file is just to allow us to do several things in our project, like run our project on the local host.

So we can see what we are building, migrate databases, and I don't want to get into details, because you might not understand now, but you understand later.

But for now, you don't want to touch this file.

So let's just close that up.

And then when we come into my project, we have an INI file.

Yes, this file is empty.

For now, there's not much to explain in this file legislatively like this.

So what's it gonna use all these files later in this tutorial, so I'm just showing you like a boilerplate that Django brings up when we create a new file, so we're gonna use this as gi is an important one.

It we don't need much manipulation in this is just one line of code or something just to assess some socket and stuff.

So just leave that for now.

And then this settings file is like the bedrock of your whole project.

So if you do anything wrong in this settings file, it's going to affect your project.

So we need this file, we need this file a lot.

We're gonna use it to like this installed apps, we're going to do some things in this, we scroll down to see where we have templates.

This is empty.

For now we're gonna do some things.

And then we keep going, Yeah, we're gonna do a lot of things in this settings file is just the file that has all the everything we need in our project.

So all the configurations, and the apps when installing anything in all our data bases is inside this file, we're gonna configure it.

So now we have this URLs dot p y file.

Now let me explain what is your spy file does this weird up to y file, what it does is what we're going to come in here.

And then we're going to specify all the URLs we want in our project.

So for example, let's say we have a website named www dot COVID tomi.ml.

Now we have that website, when a user just comes to code return mi.ml.

What page do we want to open is you are going to specify it, but whatever user goes into COVID tomi.ml slash newsletter, or slash blog post or something.

Now slash is another web page.

Another URL is here.

We're gonna specify it this year, we're gonna configure each URL we have in our project to us.

We're gonna go talk about that later in this course.

And then these Ws gi, yeah is kind of similar to the SGI.

But for now we're gonna leave this.

So right, we have all these.

Now, what I want to do, I actually love working in this command prompt.

But what I want to do now, first of all, I want to deactivate this virtual environment.

So it's very easy.

All I just need to do is type D, arc safe v.

Now you can see we're not in the virtual environment again.

But now I'm away from Java travelmate, how can I assess it back? Let's go into VS code.

In VS code, we can have our terminal our small terminal right here.

So we don't need to jump back to command prompt every time we need to do something.

So right here, you'll see that we have this terminal, it was going to give it a few seconds to load up.

That shouldn't take too long.

So right here in this terminal, we're going to Yes, this is a we're going to assess our project is ready in this project directory.

Now let's say we want to go into the virtual environment very, very easy.

We just need to do say walk on a shame of this.

And then we'll say the name of the virtual environment in Mr.

Vijay Verma was my No.

Normally, we should have something like this right here, what is not yours? Let's come into our Vish command prompt and say work on my app.

So right here, you can see that it brings out the virtual environment back that showing that we are in this virtual environment.

So in VS code, it is supposed to do the same thing, but I'm sure that is because it's using maybe another type of command line interface or something else.

But yeah, that's gonna be a minor problem.

We can just overlook that.

But this is how we can deactivate from a virtual environment and go back into the virtual environment is very easy.

So let me just quit this.

Now, what we did was, we created a new Django project, we installed Django, we talked about virtual environment, I explained all the files for this files, which was created when we created a Django project, I explained the command line interface, we've done a lot to introduce Django.

So now I'm sure it should at least have a graceful just understand what Django is about.

And now we can start working with it.

So now that we have our Django project created, what I want to talk about is the Django app.

Now, this might sound funny, but there is a difference between your Django project and your Django app.

I'm going to explain it using a popular site.

Now the Django apps are like subsets of the main project, we have this project created right here.

Inside this project, we can have multiple Django apps, so they're like subsets of a particular app.

But why would we use a Django app one, we just already have a project here.

Let me use for example, like Instagram has come to explain.

So we have Instagram.

In Instagram, you know that we have different sections, we have the feed the photo feed, we have the marketplace, we have the direct messages, we have the story and plenty of other things.

So Instagram might be the main project, just if we're using Django For this example, let's say Instagram is the main project, then we have the direct messages, that can be a particular app, another app just for only that direct message, we can have another app for the marketplace, we can have another app for the reuse, we can have another for your stories, we can have another app just for the photo feed.

Now, each app can just have a particular function is doing.

Now, in plain most projects, you don't have too much apps, you might just have one project on one app with the project, I've been doing that as well.

But if you like have a very big project that you want to do that will require plenty apps, there is no problem doing that.

So that's what apps are in Django, they the main project, and they are the subsets of that project, which are apps for different features.

You can also have one up your one project or one up and you can just have multiple features.

That is also totally fine.

It depends on how you just want to arrange your project.

But one project I want at least I will create a Django app very easy, just like we created the Django project.

First of all, we need to make sure that we are in the environment.

And then there we are in the directory of our project, the root directory.

Now when I say root directory, what I mean is the directory which goes contains the money.py file.

That is the root directory of this Django project.

So we can confirm the wind is the root directory by saying Dir.

So we see money.py.

This tells us that yet you're in the root directory.

Now to create an app does when we use this manage dot p y, in earlier I explained that this money does pure y, we don't really want to code anything inside it, but we use the file a lot for different things.

Now, creating an app is one of the times we use that money.py file, we'll just say python manage.py.

Start up.

And then we can name this my app, since I do have my project name in my app.

And then when we hit enter, is not going to give us a response right here on the command line interface.

But if we go into our Visual Studio code, by Come here, you see now that I have a new folder named my hub.

And under the I have a new, another folder and a bunch of files.

So let me just quickly go around and explain if so this in it, we really don't do much inside.

This is just for the migrations for the models, I don't understand that later.

This admin.py Django has this beautiful admin interface, which allows you to control your size or maintain your size you view or the database is everything you need to know about your site.

And this admin spy file is where we register some database you want to put in there, and some other things we want to do.

And then this ABS Wi Fi, we also use it but not too much.

But let's just keep that.

And then these modules are py file is the file where we create all our database.

Now dealing with database in Django is quite different.

Because we don't need to write a single line of SQL code.

I'm also going to explain that later in this course.

And that's what the model is a PDF file is for the tests, we we use it in some cases, but not four times, so it's not frequently used.

And these views are pure is where all the main thing, Apple.

So what we're going to look at this video, if you want in this video, is where we're gonna start from.

So now, let me just quit these.

Now, f of these.

Now, let's say we want to start with the URLs configuration.

Now the URLs configuration when I say that what I mean, as I explained earlier, I said is let's say you have a project, and then each each link, let's say you have a website like youtube.com, then each particular link is a different URL.

So that's what the URLs configuration is about, you're going to understand that in a bit.

So what we just want to do now is to configure URLs, let me just make this more understandable.

So we have this Django project.com website.

If I click on overview, or I click on downloads, let me call me I click on download.

Now you see I have Django project.com.

Slash download.

This slash download is another URL.

This Django project is calm, the main one is the main URL as the URL when what the user should see when it enters our site.

And we are slash download because I know that URL, we have to configure all of these inside our Django project that is what is called URL routing, or URL mapping, or URL configuration.

I can call it anything.

So to start with, these are not going to come into my app, and then in my app, but what are the URLs file.

So we're gonna create a new file and name it urls.pi.

And we need to import something from Django called path.

So say from Django dot URLs, import path.

Now this part is going to allow us to us multiple URLs in our list.

So we're going to have a new list called URL patterns.

And this list is going to take all the URL we have in our project.

So we can see path.

This is how we specify a new URL.

And then I just have to I think there's a called codes or whatever they're called.

And then now I say views that index I'm going to explain all of these, and then name equals to index.

So we import a path from Django dot URLs.

That is what allows us to configure each URL you can see we are using the paths that we imported.

And then we just have a new list named URL patterns.

And then we have multiple Like, if you want another URL, you can just add a new URL new arrow like that.

That is to shoot is a list.

Now let's use pat on open a parenthesis.

And then we have this empty quote or Yeah, I think, then one is empty.

That means that is the root URL.

Let's say we have something like slash download.

Slash download now means that when a user goes to our website slash download, then this is what you happen.

So but for now, when it's empty, it means the comeback, just the main sites, a main project, where we say slash download is miss our site slash download.

So for now, this is the main site, and then views dot index.

So the way you are works in Django is that we enrich your recipe file, we configure the URLs, but when a user comes to this particular URL, what will happen? Now that is going to be done in the views dot index, we may render an HTML file, we can just send a restful HTTP response, a JSON response, we can do anything.

So that's going to happen in the views.

But before we can use that views, we need to import it.

So we can see from imports, permission is correct.

Import views.

So now that we have views imported, we can say views dot index, what does this index mean? It means a function.

So these views we imported is basically just as views.py file here, when I come here, I have a new function named index, it does take a request, I'm also going to explain all of this, and then I can pass for now.

So right here, I have a function named index.

So whatever we do in this function is one is going to be assigned to this particular URL.

So this is the way it works, the user comes to this URL, and then it sees that it needs to go into views, and look for look for a function or a class or whatever called index.

And then whatever is done in that index is what is going to be rendered to the user.

And then we're just going to use name, you can make this name anything you can name it index or own, but is advisable to name it the same thing, your name in that particular URL, so you don't get confused or stock, or just get some kind of errors.

So this name is also give this like a kind of ID is the name.

So later, you're gonna see why we will give a name for now we'll leave it like that.

So let's save this file.

So as I said, most user comes to the UI is gonna go into views dot index.

And then whatever we do in this in this is what is going to be rendered.

Now what we just want to do see is what am I just doing here is what is going to be lender let's do something, let's return something.

And we can just return an HTTP response.

So that before we can read out, we have to import it from Django URLs from Django dot HTTP, import HTTP response.

And now say return HTTP response.

And then this HTTP response isn't gonna be can be like an just an HTML tag, like an h1.

And then it gets a welcome.

And then we can close that h1.

So we were just having a simple HTML code inside this.

Now, if I run my project, I'm also going to show you how to run your Django project.

If I run my project, you're going to see that we don't have anything.

So let's first of all, run our project.

Before we continue.

Let's come back into our command line and say Python manage.py run server.

Now remember, I said we're gonna use money Wi Fi a lot in our command line.

So for us to run our project on our localhost, so we can see what we are building, we need to press Python manage py run server, I'm gonna hit Enter, and then you're gonna see what's going to happen is going to run our project in localhost with a port of 1000.

So we don't need to copy this.

Comments:


    More Stories

    Cover Image for Save Content

    Save Content

    Bryan Guner
    Bryan Guner
    Cover Image for JavaScript Basics

    JavaScript Basics

    Bryan Guner
    Bryan Guner