Python Course for Beginners : Learn Coding with Replit (Part 1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to the first lesson of our Python Programming crash course we will start with the absolute Basics to get you familiar with python so what is python python is an interpreted dynamically typed and highlevel programming language it was created by Gan rosom and first released in 1991 python emphasizes clean and readable code making it an ideal language for both beginners and experienced developers why python is so popular first is because of its Simplicity python is straightforward and the human readable centers reduces the complexity of coding TXS two is versatility python is a multi- parag language which support both procedural and objectoriented programming and as well functional programming three python has a massive and active user Community contributing to an extensive collection of libraries and Frameworks four crossplatform python is available on various platform Windows Mac OS and Linux five open source python is open source which means it's freely available and open to contributions and improvements from the global development Community what is python used for python is used in web development using Frameworks like Jango and flax python is also used in data science and machine learning used in scientific Computing Automation and scripting game development desktop applications Network programming education and Etc how to install and set up python on your computer to install and set up python on your computer is super simple but for the purpose of this course we are not going to be downloading python or a code editor on our computers we are going to be using a website called replate with replate you don't need a sophisticated computer to install python however I'm going to be providing a link to a full python course where I'll be showing you how to install and set up python on your computer so without Much Ado let's simply open up our web browser and then I'll simply type rep.com and here we go so rep is an idea to software and it's fast so here it says build software collaboratively with the power of AI or any device without spending a second on setup so if it is your first time using repet you're going to click on sign up so I'm just going to click on sign up and then you can continue with Google or you can continue with email so I'm just going to continue with Google and here I'm going to choose one of my Google accounts which I want to use to create a reple account and here we go so I'm just going to close this onboarding screen and then we are going to see a button create reper so I'm just going to click on that button and then here I'm going to click on python because this course is about Python language and then I'm going to give my reple a title so I'm just going to say python python for beginners so you can call it whatever you want and then I'm going to click on Create reple and here we go so here you can see our repo python for beginners has been created and take this as a a working directory or a folder on your computer and then in that folder the repo has created a python file for me which is main.py so on this file I can do a lot of things I can rename it I can copy the URL and I can also duplicate or download or delete the file so for if I want to create a new file so I'll simply hit on this icon which is new file so I can click on it and let's call this um let's call it script.py and I will hit enter so here that I have another file script.py and main.py so the py basically tells the computer that this is a python file so every python file must end with py so now you can see I have two tabs so I'm just going to close one of this tab so I can use the main the main file and then on the left side on the right side we have the console so when so when we write a code on the main.py and then we run the code then the result will basically appear on the console now let's write our first Python program so to write our very first Python program I'm just going to delete this so I'm just going to get rid of this I'm just going to start typing my first code and this is going to get rid of this text so I'm going to say print followed by a parenthesis note repli do have an auto completion which pops up as you write your program or which pops up as you write your code but to make things as simple as possible we are going to write this code ourself so we have a print and then we have a parenthesis so and inside the parenthesis I'm going to put a quote inside it and this is a single quote and then I'm going to say hello hello Miriam and then I'm going to run this so if I click on run and here we go hello Miriam so we have so we have successfully written and run our first program we can also use a double quote for this so if I replace this with a double quat and run this again and this will give us the same result so I can go ahead and equally print a number so I can say print and then I want to print 25 so if I run this and here we go we have hello Miriam and then 25 so I can also print to multiply by five if I run this and here we go we have 10 wait a minute you may be asking why do we have quotes why do we have to include a quote on this and then we never want to include a quote on the integers now let's see what happens if we try including a quat so if I put a quod let's say we surround this with a quot and then we try to run this and here it gave us back what we wrote so here you can see 2 * by 5 so you don't surround an integer in a quot if you want to do a mathematical calculation so in programming strange are sequence of characters that enclosed in a single or a double quote so this is a strange and then this is an integer so before we move to the next step I'm going to clear my console by clicking on clear history icon and here we clear our code so I can also run this again and we'll have the same results comments are used for documentation and explanation in your code comment can also be used to hide the visibility of our code first let's look at how we can document or explain our code so let's suppose I want to document line one so I'm going to come here and then enter the ash sign and then I'm going to write this is my first first program so this is my first program so now if I run this and we got the same result now python ignores the lines that starts with a hash symbol so the python interpreter ignores the lines because it just for documentation purposes so I can also write it above my code so I can say so I can say the this is how to print an integer so if I run this one more time and you can see that the line three is treated as a comment and then it is ignored during execution now the second reason you may want to make comments is to hide the visibility of your code let's say I do not want to enas my code but I want to hide it I don't want it to appear on the console so I will simply Tre these lines of code as a comment so if I put the ash symbol in front of it and then if I execute this and here you can see that the rest of the code has been treated as a comment so we just have our first program which is hello Miriam so this is how to make comments in Python in Python a variable is a name that you assign to a value or an object it's like a container that can hold different types of data such as numbers text or more complex objects now for example let's say we have the number five now five is basically a value so how do we assign this before we continue I'm going to show you a way of turning off the suggestion by the artificial intelligence so under the TOs I'm going to click on AI and then here you can see auto complete suggest lines of code as you type so I'm just going to disable it and I'm going to close this tab and then go back to our console and this is how it should be as a beginner so we're going to type and learn everything from scratch so we don't need an AI for now so like I said let's suppose we have the number five or the integer five now five is a value we want to assign it to a variable so to assign it a variable I'm going to say x = to 5 so in this case X is now the variable holding five so X = to 5 so X is like a container that stores the number five to verify if actually X is equal to 5 or X is actually holding the number or the value five all we need to do is to print X so if I print X and then we run that and here we go we have five so I'm also going to make comment this so if you run that again and here we have five so variables are essential for storing manipulating and referencing data within your Python program so I can also create more variable let's say um this is person variable and then person is going to be equal to in quote mic so now I can print person so if I run the program and here we go we have mic variables can also be used in expression for example I can say y should be equal to x + 20 x + 20 so X is 5 that means 5 + 20 and this is going to store the result in the variable y so now instead of printing person we want to print y so we can verify so if I run this one more time and here we go 25 we can also rename varable variable now on line 8 we have the variable person which is holding mic so let's suppose in line 10 we have person as a variable and this time person is holding John so now if we print person and run the program and here we have John so since Python program runs from the top to the bottom when it gets to line 8 we have the variable person which is equal to mic and then it gets to line 10 it says oh person is no longer Mike but John so it reassigns the name to John next let's look at variable naming conventions now python has variable naming convention and it states that variable names can include letters just like we have person can also include numbers and underscore for example let's say we have another variable or let's say students score this is going to give us an error student score let's say is 100 so you can see even without running the code we can see the underlined error so this is a bad naming convention which is not going to run so in order to separate this we can introduce an underscore so that we can avoid an empty space student underscore score or let's say student scores so we have student and then we have the underscore and then the scores is treated as a variable so so we can say student uncore Mark so let's put that student uncore Mark so this is treated as just one variable and you don't begin a variable name a variable naming with a number so for example one student unor Mark so if I run this so this is going to return an error so you can see syntax error invalid decimal litra and this is coming from line 11 so you can see from the aror line 11 one student Mark so but you can include a number afterward so just like this so if you run it this is not going to produce an error so let me clear the screen so if you run that so here we go so let's print this and let's see if everything is working so now if I run this and here we go 100 also variable naming are case sensitive so let's suppose I have a variable count count uncore 1 is equal to 10 and then I have another count but this is going to start with an upper case so count underscore 1 equal to 10 so both are holding the value 10 and now if we try to print or let's say let's change this to 20 so let's say this is holding 20 so let's print the first one so we say count one and if we run this so here we go we have 10 coming from line 12 which is countor 1 = to 10 and and let's print the one with the upper case we run this and then here we go 20 so both are different variables and finally your variable name should be descriptive so you don't create a variable and then you call it a random a random characters so this is not recommended so your variable name should always be descriptive in programming a data type is a classification that specifies which type of value a variable can hold a data types Define the set of a values a variable can take as well as the operations that can be performed on these values for example we talked about X being a variable on the left hand side and then we talked about five being a value on the right hand side so let's I'm going to highlight all of these and treat them as a comment by holding control and the forward slash on your keyboard and then I'm going to give you an example of what data type is so first let's look at the integer data type integer integer data type so example of an integer data type is like a H as a variable equal to 25 so 25 is an integer so we can also create another integer data type so let's see quantity TT as a variable is holding minus 10 so this is also an integer data type so next let's look at a floating Point data type so I'm going to make a comment floating point or simply float data type an example of floating Point data type are like price as a variable and this is going to hold let's say 19.5 so a floating Point always have a decimal so when you have a variable holding something that looks like this then it is a floating point or float data type so we can also have pi as a variable and this will hold 3 point maybe 14 and this is another example of a floating Point data type next is example of a string data type so a string example of a string data type I like name equal to mik is a string data type because is quoted so when a character is surrounded by a single or double quotes is a strange so we can also have maybe message MSG call to let's say message equal to hello Nelson so these are strange data type next we have a Boolean data type Boolean ion data type and this is like let's say we have a variable check and the variable is holding through and then we have a variable let's say test and this is holding false and make sure that the first letter start with an upper case so when you have a data type with true or false that is a Boolean so we also have a nonv value so let's say we have check and then check is equal to n this simply indicates or represents the absence of a value so and all of these can be printed because they are all being stored in a variable so we can say we want to print let's say we want to print name if I print oops so I want to print name like we have so we have name equal to mic if I run that and then you can see we have mic so let's say we want to print check oh at this time check is going to be overwritten so let's say checking so let's call this checking so we print check so here you can see true and then let's Sprint checking which is going to be this so if I run that and then you can see none so these are the common data types we have in Python in future lessons we're going to be looking at other data types such as list and others in Python concatenation refers to the process of combining strange together you can concatenate strange using different method we are going to start using the plus operator we are going to concatenate two strings so for example let's say we have first first uncore name and this is going to be equal to mic and then we'll have last oncore name and this will be equal to John next we will sa fcor name and this is going to be first name and then we introduce the plus operator which serve as a concatenation and then we input a string which is going to create an empty space and then the plus operator again followed by the last name variable so here we have a string and then we have a variable have a variable and then we have a string separated by plus sign here we have a variable here we have a string an empty string and then we have a variable also and this is also separated by a plus operator so now all we need to do is we can now print full name so if I run this and here we go Mike John so this is how we can concatenate two strange if we do not include the space so let's say we have something like this if I run the code so we'll have it as Mike John so it's recommended we have it this way so that that can be a space between them we can also combine strings and number so if I turn this into a comment and now I'm going to I'm going to say age you say call to 25 and then let's say we have a message and this is going to be let's say I am space and then the plus operator and then we have the AG then the plus operator again and then we say yes old so if we run this we should expect an error so type error can only concatenate strange not integer so here you have a variable which is holding an integer value and here you have a strange you have a string and then you have an integer so the plus operator used as a concatenation does not work in this case there are two ways of solving this problem so we need to convert this into a strange so I'm just going to surround this with a quote which with turn it into a string and then now I can print message so now if I run the code and here we go I am 25 years old so we need to space this and then for run it again and then here we go I'm 25 years old if we do not want to do it this way we can use a strange function so we'll Force this into a strange just surround it using the strange function so now if I run this one more time and here we go now other ways we can concatenate string is using the F strings and this only works in recent versions of python so from python 3.6 and later in order to demonstrate this I'm going to clear the history and then turn this into a comment and now I'm going to use the FST string which is going to allow us to embed expression inside strange literals so let's say we have a name name is equal to mik and then we have age equal to 25 so we can have a message variable and this is going to use the F string we start with an F later and then a single or double quote so I'm going to use a double quat and inside a double quat I'm going to make a sentence so let's say my name is and then we introduce a a Col bracket which is called a strange liter so inside a collie bracket I'm going to pass in name which is this name equal to mic so we are going to have my name is mik and then I'm going to say and I am then a strange literal again and then I'll pass in the variable H then I'm going to say years old and full stop so now I can print message so if I execute this and here we go my name is Mike and I am 25 years old so the strange literas enables us to concatenate variables and expressions next we can use another method called string formatting so I'm going to turn this into a comment again and now and now to use string formatting we're going to create a name variable and let's call this Alice and then let's also have H and Alice is 30 next we are going to create a message equal to in quot my name is then a call brackets and I'm going to say and I am followed by this I am years old and then after the quot I'm going to add a DOT followed by format the format function and in the first col bracket I'm going to say my name is Alice so the first is going to be name variable and then we have the second one I am and I am I'm going to have the age go into this so now I'm going to add the age we can print message so if I run this and here we go my name is Alice and I am 30 years old so what if we want to say and um this so let's try to run that and here we have the same result now what about doing the same thing on the previous one if I remove the comment and now I'm going to say I'm apostrophe M so if I run this and we have the same results what about doing the same thing right here so let's try that so so instead of this so I'm going to say I'm apostrophe and if I run this we should expect an error and here we go we have an error so in this case python is basically confused because it doesn't really know which is coot and which is an apostrophe so in order to escape this error so we need to add a slash and this is going to escape that error so if we run this and here we go I'm 20 I'm 25 5 years old so let's clear the screen so you can see everything let's run the three examples we run that and here we go I am 25 years old so these methods provide alternative ways to concatenate string in Python and so far we have seen that each had its own advantages depending on the specific used case condition conditional statements in Python are used to make decisions in your code based on whether a condition is true or false and this statement allows your program to take different actions depending on the data it encounters first let's look at the if statement let's say we have a variable age and age is going to be equal to 25 then I'm going to say if age as a variable is greater than 18 and then a colon and then we hit enter now you notice where the C of starts once we have a colon so this is what we call indentation in Python so the our line of code has been dented so anything written afterward becomes the body of the if statement so we need to follow the indentation provided by the editor so I'll continue by saying if age is greater than 18 then print so we want to print in quote you are an adult so now if you run this code and here we go you are an adult so here we have a condition if age and we know that age is equal to 25 so if Agee is greater than 18 which is a condition then the code inside the condition is going to run so which is this so we have a code inside the condition which is this code that has been indented for us so if we do not follow the indentation it means that this code is incomplete and is not part of this condition so basically if we run this it's going to give us an error so you can see indentation error expected an intented block after what if statement so we need an intented block after if statement which is the block that will get executed so we run this again and here we go so let me clear the history run this and here we go so anything that we put inside if statement is going to run if it evaluates to true so as it stands now it evaluates to true so but if I change this to a less than sign this is not going to evaluate to true because basically age is 25 and we are saying if age is less than 18 and age is not less than 18 so if we run this we are not going to see any results let me clear the screen for run that again and here you can see this line of code does not evaluate to true so because it doesn't evaluate to true the next indented block is not going to run because it doesn't evaluate to true we also have if lse statement so let's comment on this again and I'm going to create the age variable again and let's say the age variable is equal to 15 and then I'm going to say if H is greater or equal to 18 our colon and then we want to print you are an adult after that I'm going to hit enter and then I want to make sure that it's in the same line with the if statement then I'm going to say else colum hit enter on your keyboard and then I'm going to say print you are not and adult so if we run this code and here we go you are not an adult now why do we see this instead of the first print we have the age variable which is equal to 15 we have an if condition which is checking if age is greater or equal to 18 and from the screen age is not greater or equal to 18 but rather age is 15 so that means this block of line is not going to run so we we shouldn't expect this to get printed so since this is not going to be printed we have an else so that means if this doesn't evaluate to true then else print you are not an add so that is why we are getting you are not an adult so let's say we don't have this so if I print this is let's clear the screen if I print this it's going to R return an empty result because this doesn't evaluate to true so and in programming it's not really recommended to to return an empty screen to your users so that is why we have the else block so that when your first statement does not evaluate to true what next then print you are not an add or print whatever we wish to print next we have the El statement which is combining conditions so I'm just going to comment this again so I can explain the next one so let's suppose we have a variable called score and this variable is going to hold 80 for example and then I'm going to say if score if score is greater or equal to 90 print you had a next I'm going to check for the next condition so this is like another version of the if statement so checking for the next condition which is using El if so El if score is greater or equal to 80 then we want to print youu you had B then else print you got a low grid so now if I clear the screen and run this and here we go you had B that because score is actually equal to 80 and this is the same thing as saying equal equal to so the equal equal to is used for comparing things so we don't use one equal to one equal sign just like this is used to assign a value to a variable but when you are comparing things you can use the double equal sign so if I run this we are going to have the same result you had B so basically we are checking for multiple condition so which is the E and the El if we are checking for multiple condition if the first condition is true then it's going to print you had a if not it moves to the next condition which is the El if block and then if none of this evaluates to foral is going to move to the last condition which is else so let's suppose we have 70 for example so which is not greater or equal to 90 and which is not also equal equal to 80 so if we run this and here we go we got a low grid we can also extend our conditional statement by creating a nested conditions let's suppose we have a variable X which is equal to 10 and then we have Y which is equal to 5 now we can say if x is greater than Y which we know that X is 10 and Y is 5 so 10 is actually greater than y then we are going to write another if statement inside this existing if statement so this makes it a nested if so we say if x is greater than y then we want to print in quote X is positive and greater than y then I'm going to say else print in quote X is not poity so here I have an if statement and then I have an else next I'm going to create else and this is going to be for the first if statement so I will say else print in quote X is not greater than y so let's run this and here we have X is positive and greater than y so the first condition is checking if x is greater than y if this is true then this block of code is going to run otherwise this will be ignored and then the else is going to run but because X which is 10 is greater than y then this block of line got executed and that is why you are seeing it here x is positive and greater than y so so as long as X is greater than y then check if x is greater than y again or we can say if x is greater than zero think that will be better so if we run it we will equally see the same result because X is 10 so X is still greater than what zero we have checked for this and this evaluates to be true and now we want to check if x is greater than 20 so if you run this can you guess what is going to be printed let's try that and here we go X is not positive this is going to be printed because X is not greater than 20 so this line will be ignored and then this will get printed now let's suppose that we have y let's make y 20 or let's make y 15 at this point Y is greater than x this condition will be false it won't evaluate to true because X is not greater than y so guess what is going to be printed the L's block X is not greater than y so let's try that so if we run this and here we go X is not greater than y hope this is clearer to you if it is not pause the video and rewatch if you haven't subscribed to this Channel please do well to subscribe and turn on the notification Bell so you never miss a video thank you for joining me and happy [Music] coding for
Info
Channel: NextTechGem
Views: 20
Rating: undefined out of 5
Keywords: beginners tutorial in python, learn programming, programiz learn python, python basics, python full course, python tutorial, python tutorial for beginners, web development
Id: Qrl7e3jIV_A
Channel Id: undefined
Length: 46min 46sec (2806 seconds)
Published: Tue Jul 16 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.