This Python tutorial covers essential programming concepts: (1) Input method captures user data as strings by default, requiring type casting with int() or float() for calculations; (2) Type casting converts between data types using str(), int(), and float() functions; (3) f-strings provide efficient string formatting by embedding variables within curly braces, eliminating manual concatenation; (4) Conditional statements (if, if-else, if-elif-else) enable decision-making in programs, with code blocks identified by indentation and only one block executing per condition set.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
Session#3 | Input, Type Casting, f-String & Conditional Statements Explained | Beginner to AdvancedHinzugefügt:
Okay. Uh so guys in previous two sessions let's see what we covered. Uh so first about uh the Python then you installed Python then created a project created files you you learned like this Python is case sensitive how to create your first program and how you can execute that uh program with five different ways. This is what we covered in the session number one. In session number two about the variables, constants, executable lines, non-executable lines, single line command, multi-line commands, string handling you covered. Right? Right. Uh we covered three different ways.
>> Who is this?
Please put yourself everyone. Okay. Then you learn about the continuation. You learn about type casting and concatenation. Somehow we started it but there are multiple things also. Okay.
Now uh in session number three we will be starting with concatenation.
Uh session is session number three.
This will be the more important session right for your data handling purpose. So session number three. So I will be starting with uh concatenation.
Okay. uh multiple ways you will be learning and then the input type casting and here concatenation and then f string as well.
Okay. And uh after casting the conditional handling more important all data will be uh handled around it.
Okay. Uh multiple ways in the conditional handling you will be getting each and everything. If you don't know you are zero I'm sure you will get 100% to it. Okay.
Now uh I will start with concatenation first. Okay. So this is day three. Let me close these two files. this one.
Let me create another Python file.
Concatation.
Okay. Concatenation. When you need to combine multiple values together, this is what the concatenation is, right?
Whenever you need to concatenate multiple values together then you need concatenation right. So like you have two values a equal to uh let's say uh 100 b = let's say 200 c = to let's say 300 okay if you need to combine these three values together somewhere in one print statement in one print statement if you want to combine together you you will have to row then you need to use the concatenation concept. Okay. So concatenate how we use the concatenation concept in Python under the print statement there is a rule base rule all values must be in string format.
Okay. If those are in string format then you can this is values.
Okay. If those are in string format then what you can do? You can combine together with the help of plus sign.
Okay. Let me increase the size.
Okay. Now right now you have these three values you want to combine together. So if there are the variables like this you can use in a simple and easy way without using the plus sign the variables can be used easily like let me use the print statement print let me type here I want to print like a equal to 100 dot b = 200 then c= 300 100. So a equal to this is what this is what the uh string is right and this is the integer value saved in this specific variable a right. So what you can do you can have first string a equal to give the space then comma the variable can be used directly after the comma right like a so the value of a will be printed whatever will be saved in a what is the value in a 100 so a equal to 100 will be printed let me execute this program and let's see So a equal to 100 is printed. Let me give one space between a and equal to. So a equal to is what? A string, right? So you can use the string and you know like a string should be either in a single braces string handling in the previous session we have covered right string must be either in the single quotes within the double quotes or within three times double quotes that's your choice right what you are going to use. So here this is the we are using here double quotes. So this string within double quotes then the value of variable. So variable should be always without single quotes or double quotes.
Right? If you will be using here this as an single quotes or double quotes a and you will try to execute your program and you will see so this will be considered as an string now not a variable.
Make sure whenever you will be using variables in a print statement, variables always will be coming directly. Don't in don't use single quotes or double quotes for the variables otherwise that will be considered as an string only.
Okay. Now this is what the one let me execute. Now the value of a will be considered as in 100. Right? Similarly, you can print this B as well. Right? In the next line as well like let's say print B equal to the value of B C equal to C variable. So you will be getting these three variables value like 100, 200, 300 and the strings A equal to 100, B = 200, C= to 300. So this is the concatenation of string and variables.
Okay, if you need to concatenate multiple strings together, use plus sign. If you need to concatenate a string and variable, you can use simple comma and print it. This is one of the way. If you are not using plus sign, the other way like you learned in the previous session, if you are not you, if you are using comma, that's okay. You can use the other way as well with a plus sign. But if you are concatenating with the plus sign, make sure everything will be in a string format.
Now a equal to is your string. B is and then a A is a variable. A is holding integer value. So make sure you are using string value. This if you will just try to execute this program, you will get an error. Can only concatenate a string not integer. This is what the base rule is.
You can concatenate with the help of plus sign only the string values. So you can convert this string this integer value in string. What was the function in the previous session? We have seen string >> function string str is a function you can use to type cast any value to convert in >> into string string format. Right?
Now if you will try so first is your string plus second is also your string.
Now string plus string you can convert both are in the same format right. So let me execute and see here a equal to 100 this one right. This is what you are getting guys. I mean what I mean to say if you have multiple strings together you have to use plus sign.
If you are using variables and string you can use simple comma your string comma variable print it that will work easily. Let me take one good example and you will get it. Okay. So uh instead of this let me create another file let's say okay now let me try to take input from the user like the first name last name salary age and let's try to concatenate those.
Okay. So first let's use input I will ask user to provide his first name. Please enter your first name.
So he will enter. Now then I will ask user to provide his let's say age.
Please enter your age.
In the third line I will ask user to provide his salary and the last is city. Let's see.
Okay. Last will be city.
So I will ask user to provide these four details. Now user will be entering.
Okay. User will enter these four details. Now what I will do guys?
I will now execute my program. When I will execute I just execute is asking please enter your first name. Let me try to enter let's say Yogesh.
Press enter.
Asking is let's say 40 years.
Press enter.
Salary let's say five lakh.
Press enter.
Now city let's say noa.
Press enter.
Now program executed successfully. No outcome. So basically you asked user to provide the values. He provided the values. You are not using the values.
Whenever user entered his name that name was stored here in the memory in this line number two when you asked user to enter his age he entered his age that is saved in the memory in line number three when you asked user to enter salary he entered and that's in the memory here in line number four when you asked user to provide his city he provided and that's here in the line number five and the program ended because you are not using those values that's why those are in the memory and program ended in between right now what will happen now what you can do you can save these values somewhere in a variable and you can use those later on okay let's say this is a name variable I'm going to save this first name in the in a name variable This is your age. Let me save age in a age variable.
Now salary. Salary I will save in a salary variable. And this is your city.
City I will save in a city variable. Now I user will enter I will save every value each and every value in a different variable. Now I have these values. Now my requirement is I want to print like username is is whatever will be okay then dot his is is whatever will be dot he is getting salary right whatever will be the salary he's getting right and He is staying in city right. So wherever you are using these question mark the variable value should be coming here.
Okay now before jumping to this particular logic I will use some basic concept first. Okay. And you will get one concept about the input of the user. Like for an example, you are getting here monthly salary.
Enter your monthly salary.
Okay.
Now I want to calculate annual package.
Calculate annual package. And let me use here bonus as well. Bonus input. Please enter your bonus. So calculate annual package. So annual package formula is 12 multiply salary plus bonus.
Right? This is your monthly salary. You are getting monthly salary from user.
User will enter monthly salary. You will multiply by 12. And if you're getting any bonus, you will add that bonus in your monthly salary and then that will be your annual package. You can relate your with your package.
Okay. Now let's try to calculate this first option.
Okay. Now let me try to uh execute this program again.
One second.
Uh, got stuck. Huh? Okay. Now, enter your first name. Let's say Yogesh. Enter your age. Let's say 40.
Enter your salary. Let's say five lakh.
Uh, enter your city. Let's say Noida enter your bonus. Let's say three lakh for an example. Okay, I will enter. So still I just saved these values. I didn't calculate. So these values are here in the variable. Now let me calculate the annual package. Okay. So annual package.
Annual package will be salary multiply 12. So here you have a salary salary multiply by 12 plus your bonus.
Right? This is what the calculation will be. You can save this entire calculation in a variable. Let's say annual package a package.
Now you your final calculated annual package is saved in this particular variable. And now you can print it. So print your package is this. That's it.
Any doubt guys? Anyone till here on this? Anyone?
>> No.
>> Okay. Now I'm going to execute this and let's see how this will be calculated.
How this will be now you will get one additional concept from here. So name yog monthly salary city bonus.
Okay. Now see what is this your animal package is this what's going on now try to understand whatever value user will enter whatever value user will enter the format of the value will be always string format like name he's entering that will be in a string Age age is 40. He is entering here is 40. But the format of the data will be always in string format. He is entering the salary five lakh. The data type of this value will be string. Right? So all the values try to understand one concept. Whatever value you are getting with the help of input method the format of the data will be always in a string format.
Okay. So here you are performing certain calculation string multiply by 12 plus you are adding a string. So means concatenation. So first salary multiply 12 means this is a string and you are multiplying that string by 12 times. So 12 * 5 lakh printed then at last you added bonus in that string. So here is three lakh. So this is what you just played with a string not an integer values but you have to handle you need to consider that as an value this salary and the bonus you have to calculate something. So always whenever you are getting you want like any string value or any decimal value you will be getting from the user and you understood like you are taking those values with the help of input method. So by default that will be in string. You have to convert that always first in integer.
Okay. So so here salary equal to int of salary. Int of means you are converting this salary. Salary is in string format here. So salary you will be converting in integer. Int of so int is a method which will convert the string in integer format. Similarly, you can convert the bonus as well. Bonus in integer format.
Right? So, bonus you are getting in line number six in string format that is saved in bonus variable. So, bonus variable will store the string value.
So, you are converting here that bonus in string uh in integer. Okay. So, the salary you converted in integer saved in salary variable. Bonus you converted in integer that is saved in bonus. Now you are using here salary and bonus. Now that will be calculated per factory. Now let me execute my program.
Enter first name Yogesh. Enter age 40.
Enter your monthly salary five lakh. Enter your city NOA bonus let's say anything.
So you are you calculated your bonus or your annual package that is 63 lakh. So 5 12 60 + 3 lakh is a bonus. So 63 will be final annual package. So what you understood? You understood one concept.
What is that concept? The concept is the value whatever you are receiving from the user those all values by default are in string format. If you need to perform certain calculations for any uh integer values which you know like you are receiving you want those as an integer format then you have to convert those values in integer format then you can calculate you can perform your calculation and start to use those right so hope this is clear now uh is it clear to everyone now then I will move to uh two addition concept on this.
>> Yes.
>> Yeah.
>> Yes.
>> Everyone.
>> Yeah.
>> Okay. Let me ask in a different way. Is there anyone who has any doubt on this?
Anyone?
>> Uh yog.
>> Uh yes, please.
>> Okay.
>> Yeah. Tell me.
>> Uh okay. Yog. So uh just had a doubt like if the number is integer we have to uh type cast it to int here right. So in case of date and float values do we have to use float or like >> perfect. So if you want to convert in a float so float is a uh function over there.
>> Okay. Float is a function which we have to use here.
>> Yeah. Like integer is a function to convert any value in integer. Uh string is a function to convert any value in a string. Float is a function to convert any value in a float.
>> Same would be for date, right?
>> No, for date there is a different concept. I I will cover separately that.
>> Okay, sure. Thank you.
>> Uh yeah, Supria, I think you were asking something.
>> Yes. Uh I have a general question like uh here uh so whenever you are typing code you get the suggestion directly like whenever you click the type salary you got like uh integer function and the salary automatically. So it is it just a pycharm feature or any no I okay let me tell you like this is what the paid version I'm using this pycharm okay you guys may not be using the paid version.
Oh >> okay. So actually otherwise that we this is the new actually before Diwali you know last year they were giving uh the community version for the lifetime use but now after that they are just giving for one month uh license only later on we need to either uninstall or install I mean we need to manage otherwise I mean that's really tough for me nowadays. So I took the license and I'm using it.
>> Yeah. Yeah. I just I was just curious like whenever you say something and it gives auto suggestion. So I just wanted >> You can also turn off that also, right?
Uh that's okay. I mean that's fine.
>> No no that's not an issue. It it it was just my curiosity. How is it like uh paid or is it just PyCharm related or other?
>> This is this is paid this is paid related to PyCharm, right?
>> Okay. Okay. Okay. Good. Thank you.
>> Yeah.
>> So, uh now actually I can't you are not audible man.
>> Okay. Okay. Go ahead. There is some issue.
>> No can't hear.
>> Hi. I have one very >> uh in the previous example uh when we were using plus symbol right. So actually that concept uh I didn't understand actually looks like uh if you don't use plus symbol obviously I mean uh the value string value is getting displayed in the previous example >> what symbol work >> uh for example if a is equal to 100 and uh >> variable you you mean to say variable >> yeah correct correct >> okay uh don't worry variables we will be using two additional concept now just so you will be getting everything about it right multiple things will be coming related Okay.
>> Okay. Yeah.
>> Yeah. Uh so let's see guys. Now I will be using the same example in two different ways. One is your main uh concept which I have written already uh this particular this particular requirement I want to print in this specific format. Okay. Now here I'm going to use a concept of concatenation and then I will be printing it. Now so there is two things.
Let me comment this specific value. Okay specific line. Now here let's get this requirement done. Okay. So here you have all these variables.
Now let me use the print statement in print. Now so first username is let's use this. This is your string.
So put your string here. Now you will have to give the username.
What's the username? Username is available under the name variable. So use the plus sign plus name.
Okay. Now after that there is a dot his is again a string. Let's use the string here plus.
What's his is uh his age is you are saving in a variable here in the is variable. Let's use the is variable now plus next he is getting this is a string put here in the string plus his is he and he is getting he is getting what salary salary is here in This variable variable will be coming as it is plus. Okay. Then he's staying in again the string.
This is the string plus he is staying in which city? in any city that will be stored here in the city variable. So you can use the city variable at last.
That's it. We are done. Right? So this is what we are done. This is the requirement which I was supposeding to complete.
Now try to understand try to understand this program I am going to execute. Try to understand these first five lines.
Okay. Then the next line and this is what the requirement is and this is what the outcome I will be getting. Now I want to see like uh okay. Uh so do you think this line will work?
So, will it work?
>> Um, sorry, Yogish. Uh, actually I'm traveling. So, is my voice audible?
>> Yeah, that's fine. That's fine. That's okay. Vinod. Vinod. Will it work?
Vinod.
Okay. Step one premod will this line work >> premote. Great. So, oh yeah. So, we have converted the salary and bonus also in integer, right? And they both that will also be considered.
>> So, what what where I mean where will be the failures in this line if anything?
>> I think it will fail.
>> Uh there's no provided.
>> Hey, one second guys. I I whatever name I will call please speak otherwise everyone else please put yourself.
Okay. Uh anyways so again let me tell you guys we are using here plus sign. Do you know the base rule of plus sign >> string >> should be in string format.
>> All values must be in string format. You have these strings whatever in the double quotes. First thing you are good.
Now you need to check the variables. The variables values are in string format or not. Name yes name you will be receiving in a string format. Age yes age you will be getting in string format with the help of input method. Salary. Salary you are getting here in the string format but later you converted in integer. So this is a latest value of salary variable here in integer format.
>> Integer value >> right. City city you are getting here with input method in a string format. So all variables all values are correct except the salary one salary you converted later in integer format. What I can do? Let me execute this program and see. So the first name let's say yogast name uh the age let's say 40. Salary let me put anything. city let me put no let me put here anything and here you will see the values so what you are getting the error error is in line number 16 line number 16 is your print statement right and you can see can concatenate only the strings not integer right you know what is in integer only the salary so this salary is in integer format you have to convert in string format. Right?
So, so we have here a function which will convert integer to string. If I need to convert anything in string format, we have a function. We learned in the previous session what is the function?
>> S str >> right. So you can convert this integer value in string format and then you can print it and you will see like here yogish 40 let's say something let's say no let's say anything and you will see final outcome is here right this is what now you can do like you are going to work in a data domain guys right hey uh who is this uh Krishna could you please lower your hand if you don't have any query man uh it's continuously >> oh sorry sir yeah >> now try to understand one thing like you are going to work in a data domain there may be 10 column there may be 20 column there may be 30 column do you think you are going to use like this like the concat you will use the first string then you will concatenate the next variable like this then you will concatenate next value then next variable you will add then if something is there you need to convert in string format I mean if there will be n number of variables maybe 10 maybe 20 right maybe in between strings will be there you need to convert multiple variables in a string format time taking activity it will it will reduce your performance of your logic dramatically.
This is very oldfashioned. We don't use it.
Okay, we don't use it. We use nowadays F string concept.
F string concept in the data domain we usually use in automation, right? That is very fast, super duper fast. We don't need the conversion right we don't need to concatenate multiple values together that will be automatically handled no conversion required nothing and the same outcome you will be getting with the help of that okay >> you guys can you hear me sorry to interrupt you hello >> so hey uh please put yourself at mute one second let me complete this topic then you can ask okay so this is The app string concept will be used everywhere wherever you are going to deal with in a data domain right otherwise if you are going to use such kind of logics that is not going to work 10 20 record 30 100 record that's okay if you are going to use 100 record million of records will fail you will keep waiting of outcome outcome will never come right now string concept how you can you achieve the same outcome with the help of F string concept That nothing simple easy way right just use the same okay like first what you will have to do you you will have to use your let's go one by one otherwise you guys may get confused let me comment this first print statement okay now user name is so what is the username Username is your name whatever will be right. So username will be in your variable variable is your name variable and the name variable will be coming here right. So name variable you will be using instead of like how you used it previously either you usually use separately like this or you usually use with the help of plus sign. These are two methods you use but with the help of string we don't need to concatenate like this we usually use within the string only. So what is your variable name that put here in this so username is this name but if you will try to print this name this will be considered as an simple string. Okay. Uh let me remove some lines guys here otherwise I need to enter all these values every time. Okay.
So this bonus or let me comment some of the lines. Right. So this bonus let me comment it. Comment this bonus comment.
Okay. Can I comment anything? Let me comment the also. Okay. Let's take these three values. Now let me execute my program.
And here the name let's say yog salary. Let me put any random value.
city let's say no so your name is so this name is not considered as an variable this is considered as an string I want like this name should be considered as a variable so if you want make sure this name this is a variable if this is a variable you want you want this should be considered as an variable make sure this should be within a curly braces okay like this.
So again if you will try to execute now still that will fail I mean it will consider as an string as well. Okay, like this first name let's say yoga here username is curly braces name still this is considered as an string only you want you want like this should be considered as an variable yes I want then what you can do this is in this braces you have one string only and why we are This is a string because this is within the double quotes. So if you want to convert this in f if you want to convert this as an string as an variable so you have to convert this entire one string in f string format. How you can convert? You have to just add f before your string. Now I just added f before the string. See the variable name got highlighted now.
Right? If you will try to execute your program.
Okay. Uh name Yog. Oh, sorry. Let me enter here. Name Yogesh. Press enter.
Let me put any random value. Let me use.
Sorry. See username is Yogesh. So this is considered as an variable. Now how this is considered? Because the entire string you convert in f string format.
How you converted in f string format?
You just added f before it was a string.
Right? So if any any uh thing you want that should be considered as an variable make sure that should be within the curly braces. Right? Let's take let's add something else also here in this.
Right? So let me use comma sorry here comma what is the next uh username is this and he is getting right uh and his age is we are not using we are using let's say salary and he is getting let's say he is getting he's getting what he is getting salary right where is the salary here you have salary You can put the salary here. Now this is the salary. This is as of now a string right now. How we can convert this in a variable?
>> We will add curly braces.
>> Yeah. Yeah.
>> Yeah. So we can use this variable within a curly braces. Right. So let's have this in a curly braces.
Right? Now this is highlighted. Right?
You can add comma just after this. And just similarly the third value is what?
CT. Right? And he he's staying. Let me copy from there. He is staying in.
He's staying in. Then the third variable is city. Put it here. City. Now you want to consider this as a variable.
Make sure you will be using this within curly braces.
Right? See everything you convert in a f string format. This is one only one one string. Right? No concatenation with multiple strings. nothing right multiple variables you are using inside it so quickly those can be filtered right and how you can convert everything in a f string just added f before it let me execute this and uh name yoga you will see here username is yogis he is getting something he staying at noa so this is what is used now where you have a large volume of data. So concatenation conversion in uh any different format of the data that takes time we don't have time to wait that for that right so this is what it is you should use guys okay uh yan now you can tell me you were asking initially something >> yeah can you hear me okay now >> yes I can hear >> so in line number 16 now why we need to convert this uh data type into a string str we can uh can we use comma instead of plus operator without any conversion.
>> Huh? You are saying why we are converting this?
>> Yeah because uh yeah this string this salary attribute into a string. So we can uh simply use comma instead of >> yeah I mean this is what I already told there are three ways right? Two ways at least like you can use comma as well but I used I was trying to tell this concept >> right? If anything will be in integer and you are using plus sign you are concatenating with plus that will fail.
You need to convert that.
>> Okay.
>> Right.
>> Where do these things?
>> Okay.
>> Uh you one big dot. Suppose if I put after plus if I put comma it will also work. Uh >> after plus you will put comma here in which here in this line?
>> No in the above print. Yeah >> like this. No. Uh he is getting uh here left side he is getting and plus after that if I don't use string aa >> okay here in this uh >> he is getting >> no after that uh plus >> a you want the comma something like this right like like here you can you want like this right you can you can add after this right he's getting the salary will be coming from here and here in the next string you can add this comma >> no no yish we have an other way Right?
Instead of using a plus, we can use a comma also and then we can print.
>> I mean that's okay. Okay. Okay. I got it. This is what you guys are saying and I was uh I covered that. Okay. Today also like the variable you can print with the help of the comma as well like here right variables without using without using this plus sign you can use the comma as well. That's okay. There is no harm about it. But the problem will be if you will be having the multiple values you want everything should be the cal I mean like this and you are using the comma. So I mean the performance of this will be faster compared to that like you can achieve with the help of the comma similar kind of thing but just try to understand there will be the multiple values as an parameter over there right let's say these one one string comma this variable another string this variable another string this variable another string this variable right if you are using comma instead of the plus sign so you are using multiple values use over there then finally you will be getting outcome in concatenation that takes time internally in execution are you getting it guys >> yeah yeah yeah I'm getting yeah >> yeah got it yeah >> that's why we are using this and the same question he asked uh who was that Nishant right he asked the se right >> yeah two ways there there to explain the concept that you had string yeah got it >> huh Okay. So this is what guys. So try to use always uh the f string concept. You will be enjoying your life whenever you will have the large volume of data sets.
Right?
>> Perfect.
>> Okay.
>> This is what the app string concept. Uh >> hello.
>> Uh yes you tell me.
>> Uh in line number 19 can we use a tier of salary inside the curly braces?
>> In line number >> 19.
>> Uh-huh. If we have not converted the salary to a string before can we uh >> you can use as it is whatever you I mean here it really not required you converted the salary or not whatever is that that will be coming here directly in the variable.
>> Okay. So we don't >> conversion is not required in case of app string. Conversion is required only in case of plus sign. If you are using concatenating with plus then the conversion is required. If you are using simple like the string comma variable name conversion will not required in that case.
>> Okay.
>> Okay.
>> Uh you so this fing is a function or like >> no no f string is a concept like you just added f before your string. Your string is within this double quotes right?
Okay. So it's automatically convert the variable in the desired format. Like if there is any float variable then it will convert it into the what string does app string enables the variables in your string. If those are available within the curly braces. This is what the purpose of this f is what? F string.
>> Okay. So if we have any kind of variable then if we use this uh variable in curly braces then it will recognize as variable otherwise it will recognize as string.
>> Correct. Correct.
>> Okay. Got it.
>> Doubt like uh can we uh can we calculate the package also here in this print statement with this concept?
>> Can we yeah we can we can calculate right? We can easily.
>> Okay.
>> Right.
>> Uh okay. So if we put that formula here, it will calculate and give the >> amount. Is it >> correct?
>> Okay.
>> Cut. Okay.
Okay. Uh so now let me move to your interesting topic for the day that is something conditional handling.
very important topic and critical topic.
Okay, this is something which you need it. Okay, so first you should be aware what is conditional handling what is uh under the notes that will be there.
Okay.
So what is conditional handling?
and why we use it.
Okay.
So, conditional handling. So, guys remember one thing always whenever you have you have to make a decision.
Okay. In your conditional handling is nothing. It will always the automation method which you automate with your programming and that automation program will take decision on your behalf right let's say for an example let me take very basic example everyone will easily understand okay uh let's say a login page login page everyone is aware about the login page username you need to enter your username password correct and then hit the login button so multiple there is a conditions already handled at a back end already if you will try to enter wrong username or you wrong password it will and you will hit at enter button or sign in button you will get a like username is incorrect or password is incorrect or both are incorrect. This is what at a back end it handled the condition like if user will enter wrong username give this message. If user will enter wrong password give this message.
If he will enter both wrong give this message. So means these are the multiple conditions already added over there in that application in all the applications almost right. So those all are the possibilities basically those possibilities we grouped together let's say I will say like in a login page usually uh we consider with all kind of combination all uh 21 to uh 29 positive negative scenarios for a login page for any login we usually consider these number of scenarios.
So these are the conditions over there we will be putting we will be adding over there for a login page. Basically if you will ask to the new user he will tell you two three conditions but basically at a back end we usually add these number of conditions minimum right. So condition handling will always improve your programming capabilities to make the decision he's doing something wrong or he is doing something right. If he is doing something right then do it this allow him to do to perform certain task. If he is doing something wrong block him don't give him access. Don't allow him to login. Right?
So conditional handling in the data as well. This is more important. You don't know that what kind of data will be coming or data has been loaded in target or not or you are trying to read data from somewhere but the source of target is not available over there I mean you don't know so you have to make certain conditions over there right so condition handling is used to make decision in a program based on certain conditions Right. Okay. You have three type of conditions.
Three type of conditions.
Single condition, true condition and three conditions.
Now single condition if you have only one condition then you will be using only if you will handle that condition with if only.
If you have two conditions then you will be using if else.
I will tell you I will give you the process flow as well. Okay don't worry.
Let me first give you these keywords.
Try to understand this then you will get don't worry you will be getting each and everything. Okay. So three conditions I will remove the three condition. I will use here the word multiple conditions conditions. Right? So multiple conditions in case of multiple conditions you will be using if al if l if l if else.
So remember if there is a single condition you will be using only if.
If there is two condition you will be using if as. If there are multiple conditions there will be if al if al if l and then else. Now if there will be let's suppose one condition only if will be there. If two conditions will be there then if else if here multiple conditions are there for an example 10 conditions.
So how many if will be coming? Only one.
Okay.
One.
How many al if will be coming?
>> Eight.
>> Eight.
>> And at last there will be else.
>> Else >> at last.
Okay. So remember guys as many as conditions you will be increasing al if will be increased.
Okay. So if will be one else will be one only if will get increased.
Don't worry we will be learning by example as well. But you should be aware first like single condition we will be using if two condition if else. Multiple conditions if al if al if al if al if al if and at last else. For an example 10 conditions will be there. We will start with if eight al if will be coming in between then else will be there at last.
Okay. So this is what you should be aware. Okay. So three type of conditions. single condition sorry uh two conditions and multiple conditions.
Now before starting these conditions I want to tell you a separate logic separate concept first.
Okay. Because that concept will be used here in the conditional handling concept.
The concept is group of codes.
Okay, concept is group of codes. What does it means?
So let's suppose you have multiple lines.
Okay, those must be executed as an group. As an group I will be executing for an example those all. Okay. So let's let me write here. So we usually use a technical word block for that block.
Okay. So question should be what is a block?
Because block will be coming here in single condition, two condition and multiple condition. That's why I'm going to complete it first. Block. A block is something wherever you write multiple line of codes means group of statement those belong together means as an group and executed as an unit as in group also.
So that is a block. Block means you have multiple lines but those will be executed all together as a group.
How you will identify? Let's say you have in your program in your program you have 100 lines.
How you will identify like five lines are there as a group? Five lines as in group as a block are there in within these 100 lines. How I will identify like those five are in a block and will be executed as in a group together. How I can identify? So you can always identify those five lines must be with a different indentation.
Must be with a different indentation.
Always every block will start with colon and after colon your all five lines will be started with a different indentation.
Okay. So if any line is ended with this colon and after that the next line just after that line next line like this line is starting from this right and next line is starting with some space or tab right. So these five lines are starting with a different indentation means this is one of the block dependent on this specific line and these five will get executed together if the condition will be true of this block. I mean this is high level of you will be getting now practically. Now let me go there and let's see let's try to understand now.
So single condition handling single condition uh try to understand single condition handling uh hand uh single condition first. Okay. So how that works? So basically single condition let me copy from there.
So single condition you will be writing under if so if block will be starting and if the condition will be true then the block will get execute.
So I will tell you the process flow for this. Then I will use some example for that. So I will use paint.
Okay.
And here let's try to understand the concept of your uh conditional handling of single condition. Let's say you have to make a decision for single condition.
How you will be making? So you have a condition. Let me use block.
So here let's say you have a condition for an example. Here condition can be anything right? Let me increase the size.
So here you have a condition.
So guys this specific condition may be true or maybe false like your age is I'm saying your age is is greater than 100 so that condition may be true or false right am I correct or not >> yes yes >> right so any condition may be true or maybe false you are getting your salary per month 50,000 Maybe true, maybe false. Your salary is greater than one lakh. Maybe that is true for some of you. Maybe that is false for some of you. Right? So condition may be true or false. So if you are using single condition. So in case of single condition guys if the condition is true for an example if condition is true what will happen in that specific case whatever line of code you will be writing your block right the block will get executed. This is what we were saying multiple lines, right? Block means statements.
Okay, means whatever code you will be writing there. Okay. So this is what if your condition will be true then this code will get execute and finally after execution of this your program will get hand.
So this is when the program program will end one by one like this is your condition. If condition will be true your this block will get execute and at the after execution of this your program will get closed.
If the condition will be false for an example, right? So we are learning what we are learning we are learning single condition.
So in case of single condition we are executing the block only whenever this condition is true. In case of not true we are not doing anything. If condition is false, we are not doing anything. The program will get and okay, program will not do anything. So this is what guys. So if condition will true, your program will get execute.
Finally, your program will get. If the condition is not true, we are not doing anything because this is a single condition. Single condition means you will be doing certain activity based on condition is true, right? Uh so let's come here and let's see the single condition. Let me close all the previous files.
Let's see. Uh I will take a couple of examples of this.
Okay. Now let's take one example first. For an example, let me take a number as an input from a user and I will check the number is even.
Okay, if the number is even, I will execute a couple of lines.
If number is not even, I will not do anything. Simple. My program my requirement is very simple. Okay. So requirement is I will take so let me increase the size take input from user okay as a number and we will check that number.
Check this number.
If number is even then execute two lines like uh for an example this is right number and even number let's say in two different lines I will be executing this in a print statement okay and uh if number is not even or let's say number is odd will not do anything right this is what uh we learned in the in this right if condition will be true means your number will be uh even so we will execute these two lines and program will end if number will not even we will not do anything right this is what the process process flow is so same thing we are doing here. So let's take the even and odd. You guys may be aware right?
You should be aware like the even numbers like the starting from zero two. Similarly those can be divided by two.
Correct?
>> Yes.
>> Odd numbers.
>> Yes. 1 3 >> those cannot be divided by two.
>> Two. Right. If you will divide by two the remainder should be one.
>> Correct.
Yes.
>> Okay. Perfect. So let's take the ex uh input from the user. So input please enter number please enter your number. So user will enter right. So I will save this num this somewhere in a variable.
So he will be entering it. So I by default the format of the data will be in string. I will convert in integer. So num equal to int of num.
Now I want to check this number is even or not. So what I can do? I can just use if condition if and I will put over there this variable num variable.
If num mode of two mod of two equal to equal to zero.
Okay. What does it mean? It means if the value whatever will be in the num variable you will divide by zero and the remainder will be oh sorry you will divide by two and the remainder will be zero means that will be even number you are comparing zero right if the remainder will not be zero let's say one so 1 equal to equal to zero this will be false So we will be checking that based on the input number. Now after this line I just added these colons right I told you guys here like the block the block always start at the end there must be colon then the next line those will be as a group as a block those must be in with a different indentation like you will see there like line number 10 this is in starting from a zero indentation line number 11 zero indentation Line number 13 zero indentation. Here the block is going to start right. So you will press enter and you will see the next line is starting with a different indentation. So the block is going to start. What you want to write here whatever you wants to print you can or whatever calculation you want to write you can do. So I want to do this like this is a right number and even number. I will print these two lines. So print like this is E1 number and one more line I can use print this is right number let's a couple of lines I'm using here so these lines will be as a block. This is a block.
This is starting with a different indentation, right? And this is which block is this?
This is if block, right? This is if block. So if the condition will be true, these two lines will get executed.
Okay, these two lines will get execute.
If this condition will not true, then we will not go inside this block.
Okay. And finally, let me execute this program first. I will tell you something else also then.
So, please enter your number. I'm going to enter let's say 99.
So, what will happen? Try to understand.
You just entered 99. 99 will be coming here and then that will be saved in the num variable. That will be in string format by default.
Then this num you are going to convert in integer. So in in 99 will be stored here in the num variable in integer format. Now now you will come here in line number 13. 99 more of two means if you will divide 99 by two what will be the remainder?
>> One >> one. So 1 equal to equal to zero. This condition is true or false?
>> False.
>> False. If this condition is false, we will not go inside this block. Right? We if this condition is false, we will not do anything. This is what we learned, right? If the condition will be false, let me write here false.
So if the condition will false, we will not do anything. Right?
So here, let's go here. Right? So if the condition will false, we'll not do anything. Let me press enter.
Nothing zero outcome.
Okay. Now let me reexecute this program and let me enter any number. Let's say 400. Now you entered 400. 400 will be coming here in this line in string format. In num variable 400 will be saved in string format. Now in the next line you are converting in integer format. So 400 will be saved here in integer format. Now 400 mod of two means if you will divide by two 400 what will be the remainder?
>> Zero >> zero. Now zero equal to equal to0 this is true or false?
>> True.
>> True.
>> True. If condition will be true then you will be executing your block.
>> Yes.
>> And finally your program will get executed. Right. So let me press enter now and you will see this is even number this is right number means both line get execute.
Is that clear?
Now let me add one more scenario here.
Let me add one more uh print statement.
print let's say this is out of if block okay now I am going to execute I will call some names and those will have to speak only everyone else will be keep note at yourself I'm going to press here let's say 77 I entered 77 here. Okay. I want to see the outcome of this specific program as if tell me how the program like starting from line number 10. Can you please explain?
>> Yeah. Uh so once we give the uh input, it will convert that into the int uh value and then it will do the uh conditioning in the line number 13. So if that condition is true then it would print that.
>> No no no don't see take this value 77. I entered the 77 based on that.
>> Yeah it's false.
>> Yeah it's uh like it will return false.
So it won't execute it block next consecutive line I mean line number 17 would be printed.
>> Okay fine. Uh thank you. So uh like you entered 77 here. 77 will be coming here in this line. Line number 10 that will be in string format that will be con that will be uh you know saved here in the num variable in string format. In line number 11 you converted that 77 in integer. Now num variable will store 77 in uh integer format. Okay. Now 77. Now we are here in line number 13 and we are going to compare this right num variable 77 mode of two right. So what will be the remainder? One. So 1 equal to equal to zero. This condition will be false.
If this will be false so this block will get will not execute will not do anything. Right? So we'll go in the next line this 70 right because we are not going to execute this. So let's leave it. So we will go go in the next line this this is outside of this print uh this if block. So this line will get execute only. Okay. So this is you can see this is out of if block if the condition will be true. For an example, let me execute this uh here. Let's say 1 02. If the condition will be true, so this line number 17 will not get execute, right?
>> No, your case this will execute because this is independent line.
>> Hey, your voice is low. Uh Nishan this will execute. Can you hear me now?
>> Okay, one second. One second, man.
Okay. Now, so I enter this line uh 102.
Okay. So, let's see if this 102 will be there, then 102 will be coming here in the string format. You will convert 102 in integer that will come here. 102 mode of two means remainder will be zero. So 0 equal to equal to0 means this condition is true. If this condition is true, these two lines will get execute.
Okay, once this f if block will get execute will go in the next line 70 this will get execute right. So this print statement is not dependent on this if block. How many lines are dependent on if block on this specific condition?
How many lines?
>> Two.
>> Only these two lines those will be with a different indentation you can easily identify.
So if block will have how many line dependent lines? Only two lines. Can can you guys identify? Yes, you can identify because those are with a different indentation.
Okay. So if you so if tomorrow you will join any company, you will open any code if something will be with a different indentation. So go just one by one all the lines. So you will see somewhere these these columns means that maybe else block if block maybe any kind of block right. So that those lines will be dependent on that block. If that will be that condition will be true those lines will get execute otherwise not. This is what the block and single condition. Let me execute this and you will see uh this is even number, this is right number and this is out of if block.
Uh is it clear to everyone how single condition works? The flow basically end to end flow.
>> Yes. English >> condition how conditional searching it is clear but like to um like in other language we need to close the if block so is there any is there no need to close the if block here in Python no don't go there like in other programming language you may have to use the curly braces to open and close here we don't need it >> that's why we are using a different indentation >> right >> okay Whatever lines will be with a different indentation those will be considered as a different block one block otherwise not. Okay. If next line will start from the the zero indentation means this block is closed there only.
>> Yeah. Uh sorry.
>> Yes. The same question actually even though the line number 17 is in different indentation indentation >> that is alo part of your block actually >> this is not right. Uh so whatever see the block is starting from here right columns are there correct >> correct.
>> So after that whatever number of lines will be coming with a different indentation right this line with a different indentation out of these lines only these two lines are with a different indentation means these are as a group as a unit inside this block if block right.
>> Yeah.
>> This the next line number 17 is starting from a zero indentation.
>> Correct?
>> Means this is not with this indentation means this is outside of the if block.
If I will change the indentation of this like this then this will be inside this block.
Okay.
>> Okay. Yeah. But when we execute actually it returned uh this is even number this is right number and this is out of block.
>> So so >> this is what I'm saying right? So this will this line is not dependent on this specific if condition this may be true this may be false if this will be true these two lines will get execute. If this will false this will not get execute. But this print statement will get always execute whenever you will execute your program.
>> Yeah.
>> Because this is not dependent on if block. This is a independent line.
>> Okay.
>> Yes. Yes. Yes. Got it.
>> Got it.
>> Yeah. Thank you.
>> Okay. So this is what the single Yeah.
Tell me um Yogish like u is there any way we can uh see uh like uh whatever lines it is executing like usually in C or Java we'll be able to see right it will be highlighting that is there any option to see that >> uh what you want to see executed line >> yeah so means long back I did so I I don't even remember but in C or Java we have the flexibility where it will show right it will be highlighting those lines which got executed as part of that particular program so can we see that in Python as well >> no no that's really not visible here okay >> here all lines so see I mean Python is because the there is a complicated Java is something more complicated that's why you will see over there multiple things right you need to open, close, you will see so many things over there. They made it very easy, right? So, so it's not really uh that executable lines like you will see like how many executed or not, right? If you want to see that like whatever is going to execute, you can just add the print statement just after or before that then you can see otherwise there is nothing like that like you have in Java. Okay.
>> Uh okay.
Uh no just a thought because when we go to the framework level and whenever lines of code >> there is logger we will be using the logger over there that's a different activity we will be using okay whatever executed whatever note executed there is it different story for that right we will be keeping each and every line over there that's a different thing okay >> sure thank you >> okay uh so this is what guys you will be using the these uh single conditions.
Okay, true conditions.
If you are going to use true conditions, so you must be aware first about the flow, right? So true conditions.
Uh let me open a new paint.
Okay. So true conditions. in case of two conditions. So if your your condition may be true or may be false, right? So let me use here this is if this is your block. Okay? Uh let's say there is a condition. Let me write condition.
Okay. So let's say there is a condition 25 is a size Second condition. Okay. So this condition may be true may be false.
Right. So if this condition will true for an example, this condition may be true as well. So true.
This condition may be false as well.
False.
Okay. If this condition will be true, I will execute certain line of codes. One block. Okay. So this will be my block or statements.
Basically this will be my if block.
Okay. Whatever statement I will write those will be there. Uh and uh if condition will be false there will be let's say else block else block.
So some statements will be there.
Okay. Now if condition will be true, what will happen?
Your this code will get execute if block and finally your code will get add.
Okay.
If the condition will be true, your if block will get execute and program will be end.
Okay. If condition will be false then your else block will get execute and finally your program will get end.
Okay, this is what Okay, so in case of if in case of true one block will get execute like this if block if condition will be false another block will get execute. So always one block will get execute either if block either else block that how that will get execute that will depend on my condition. If the condition will be true if block will get execute if the condition will be false else block will get execute. Now you guys will tell me there is only one condition where there is only one condition which is that condition in that particular in for that condition block both block will get execute together if and else block. Now you guys will tell which is that condition.
For that condition these blocks, these two blocks will get execute if and else both. Tell me anyone what's that condition? There is only one condition.
>> It's not possible.
>> Anyone?
>> I think it's not possible.
>> I want to know that specific condition.
There is only one condition for that specific condition. Both if and else will get executed together >> if both the conditions are true.
>> Yes, one positive condition and one false condition.
>> Condition unmute. You can unmute only if you know that condition >> and tell me that condition only. or or >> or >> in the in the condition we can use or.
>> Okay guys, in case of multiple conditional handling either you are using uh single condition or you are using uh two conditions or you are using multiple condition.
Remember always always remember if you are having 10 condition 20 condition 100 condition doesn't matter there will be only one case always one condition will be true always one condition there is no possibility like two condition can be true no possibility always one block will get execute if there is two condition three condition or 20 condition or 2,000 conditions are there. Only the first condition will get true. Whatever will be the past.
Okay. You may write some wrong conditions. You may write let's say for an example you can write you can make the condition you are free completely free. Let's say you are going to check your age. For an example your age is 35 years. You are checking like uh age less than or let's say greater than uh let's say 10. So you will be passed right? You are passing this condition. In the second condition you are uh checking a greater than 25.
Again for these two conditions you are passing it. Third a equal to a greater than let's say 30 again you are in this third condition right the fourth a greater than 35 four conditions you are passing four conditions right a greater than 40.
So how many conditions will be passed for this specific data?
Four. Right? First of all, am I correct or wrong?
>> Yeah, you wish. Correct.
>> But >> uh true, right? Uh a uh a greater than 10, a greater than 25 and a greater than 30. Uh these conditions will be satisfied. Line number 75 will not be correct. Right?
>> Yes, that's right. Okay.
>> Now try to understand guys, you are right. You made this condition that's fine that's okay for this specific data these five these four will be satisfied one will not be satisfied when you will execute your program it's not like that four conditions let's say in if you are using these if else if I mean you are using the other condition so the first satisfied condition will get pass rest all will be escaped always it's not Like that you are going to uh execute all the conditions and you will be saying yeah all condition will be no only one condition for one data only one condition will get execute if you have n number of conditions. If your data will be uh you know eligible for four conditions or 10 condition that's okay only the first satisfied condition will get execute everything else will get this is the conditional handling in condition means the only one condition can be passed at one time in one program for one data for one input only one can be executed. Okay. So this is what uh I mean I was trying to confuse you but that's fine. So in case of two conditions if the condition will be true your if block will get execute. If the condition will be false your else block will get execute. Now let's write the program for this.
Okay. So let's go there and two conditional handle.
Sorry about that. Okay. Now let's take the same example the previous example and let's add one more condition over there.
Let me copy this.
Let's add one more condition like if the condition will be true. I was just writing like this is a right even number. If the condition will be false if the number is or right so what you will say you will do something now this is odd number.
Okay. So you are doing both task now you are checking if the number is even you are printing this if the number is odd you are doing this right so let's do the same let me copy the input method as well like this we already did so let's save some time okay now my if block is going to chart I will write something. If I will divide this number by two and the remainder will be 0 0 will be equal to zero then this will be even number. So print this is even number and let me copy this even number also from there.
Okay. Now else, now I just added colon after else means else block is going to start. This is odd number.
Okay. And this is wrong number. Let's say I'm going to write these lines there. So whatever you will write here, those lines will get executed. Now let me execute this program guys. Uh enter any number. I'm going to enter 101.
Now 101. Anjeli tell me how this program will execute for this 101.
Aneli.
Okay. uh per month.
Um at client 14, it'll check the number and divide by two that is not equal to zero. Um then it'll execute the else statement.
Then um then it will print it as odd number.
>> Okay. Fine. Thank you. So guys one second.
Okay. So I entered here 101. 101 will come here. By default that will be in string format.
Here I'm going to convert 101 in integer format. That is saved here in integer format. Now I'm going to check the condition 101 more of two means what will be the remainder? One will be remainder. So 1 equal to equal to0. This condition will be false.
>> Yes.
>> So we will not go inside this if block.
We directly jump to the next condition.
If the first condition will false, we'll go to the else. The next block, the next block will get execute. If the condition will be false, else will get execute automatically.
We don't check the condition there.
Condition will we always check in if block. Let me show there.
We check the condition there. If the condition will be true, if block will get execute. If the condition is false, your else block will get execute automatically.
Right? This is what it is happening here. Now, let me press enter and you will see this is odd number and this is wrong number. These lines will get executed.
Is that clear to everyone?
>> Yes.
Okay. Now, uh I want to print this number as well. Whatever number is there, the number I want to print there.
Okay. So, the number I want to print.
So, what I can do? I will be using always F string, right? So, I want to use the F string concept here. Satya tell me how I can print the number here using the F string. Can you convert?
>> Yes. Yeah. after print right I mean before uh double quotes we can give the f >> okay let me add f okay now >> and this is even number and then we can give curly braces as in inside that curly braces num >> num okay perfect let me use num there this is what you want >> yes >> okay and in the next line odd number >> yeah same like uh >> the same way we can use there as well >> okay So this is what guys you can convert this in f string. Let me use f.
So these two highlighted let me execute and let's see. So this is let's say 1,000. This is odd number right. Let me print. This is even number not odd number.
Okay. Okay. So 1,00 will come here.
Converted in integer compared here.
Right. So divide by 2 will be remainder zero. So 0= to equal to0. This is this condition is true. So means this is even number and the number will be printed 1,000. Right? This is what you are printing here. This is even number and this is right number. So is that clear guys? like how you guys will be using uh app string and two conditions and all uh these old things single condition two conditions is is this concept clear to everyone.
>> Yes sir.
>> Yes.
>> Uh multiple conditions little tricky. I want to uh clear that topic with three four examples. Okay. uh that will take time uh so let's take that in the next session uh next weekend okay uh so meanwhile uh I'll be sharing couple of examples related to the app string and uh these conditional handling conditional handling don't skip guys this will be your backbone I mean all the data all the decision making power is inside this conditional handling all decision making and you need like AI also that's taking decision on real time your automation all everywhere right that's making the decision automatic so everything that is based on these conditional handling only right so what I want this should be on tips okay I will give you all real time examples I will be giving you a couple of examples okay uh not today uh maybe tomorrow or day after tomorrow I'll try tomorrow you should be getting it okay uh so you guys can practice and meanwhile whatever we covered today you can try to practice meanwhile with these so that will be helpful okay so let's close it here and uh let's meet at 11:15 just after 30 minute for SQL session okay let's do something over there as well I don't want to cancel okay so okay uh see you guys after 30 minute then thank you thank you thank you thank you thank you thank you sir
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











