This comprehensive Python revision session covers essential programming concepts including falsy values (None, 0, empty strings) that evaluate to False in boolean contexts, matrix generation using nested loops where outer loops represent rows and inner loops represent columns, dictionary operations with conditional updates and nested key handling, exception handling with try-except blocks for error management, file I/O operations including seek(), readline(), and read() methods for precise file manipulation, class inheritance with super() for accessing parent class methods, recursive dictionary traversal for hierarchical data processing, and set operations (intersection, union) for data categorization and filtering.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
ET Revision SessionAdded:
Which option will be true? Which thing will be printed?
Anyone?
D. Why do you think B D will be printed?
Any of you can explain why do you think uh option D is correct.
>> So because none zero all these are falsy values.
>> Yeah. So if we use none zero or an empty string if we convert them to boolean we will always get false. So for these we are getting false for these we are getting false and uh else is basically saying that if true so if true is true so we are printing this thing so that's why option D is correct okay no doubt in this one right okay so let's move to the next question again we have an M MCQ so here again we Also a code is snippet and at the end of the execution we will print something.
Over here we are printing something. So we have to tell which option is the correct one here.
So which one do you think is the correct option?
40 that is option B. Why?
>> So C first update value will make C4.
>> M yeah.
>> Next will make it six. So 4 + 6 10.
>> Okay. And then a is already two. So 2 + 2 4.
>> Okay.
>> Sorry. Two. Yeah. So >> and then we are just adding the values.
>> Yeah.
>> Any doubt in this one?
>> Okay. I hope not.
Then we have uh question three. Again, this is an this is uh MCQ. So, which one do you think is the correct option in this one?
Anyone option C.
Okay. Why do you think option C?
>> So D will be 1 2 3 4 and then 5 6 as a tuple.
>> Okay.
>> Then E is D of 2 colon. So it will start from 3 4 and 5 6.
>> Okay. All these values.
>> Yeah. And then F is D till 2. So it will be 1 2.
>> Okay.
>> And then E of two. So E of two is the triple 5 6.
>> Yeah. E of two is this one. And then we are just uh adding those values.
>> I think >> that's why we are getting options. Okay.
Any doubt in this one.
Okay.
And uh can you guys uh uh check whether we are you are able to access the form or not? I have shared three forms. So are you guys able to access it?
All three of them.
only two is showing I have okay yeah I pinned the third one as well error in opening form two what error are you seeing not accessible or Why you go?
Okay.
I've shared uh the link again. Try that for form two.
What about form one and form three? Are they working or no?
Okay. So, uh these three forms are mandatory for ES students and I would uh encourage the DS students to also try that all the forms. Okay. So, try to solve them and submit before the session here. Okay. Uh next question. So this is again uh MCQ and here we are given a matrix and uh select the coded snippet that will generate the output. Okay. So there are some coded snippets given and uh we have to mark the snippet that will generate uh the matrix that we are seeing above. Okay. So this matrix.
So which one do you think will do the task?
Anyone?
Which option is the correct one?
Okay. Uh let's try to see all the options collab.
Over here uh we have uh two loops this one and this one and uh the matrix is getting created using this.
So when we do I + J + 1 into 3. So let's try to see what we will get as the first element. Okay.
So we will have a matrix and there will be three elements.
So first we are trying to see what we will get at this index. Okay.
So uh for that what will be the value of I and J? Both will be zero. Right.
And uh if we try to evaluate this expression when I and J are zero what we will get?
>> Three >> three. So this option is incorrect right because the first element is one not three and we are not getting that. So this option is incorrect and uh just to show that I'll just show this output. So we are getting three four five and this kind of thing. Okay, you can evaluate uh the letter elements of the matrix but uh that would take a bit of your time. So if you check the first element and it's not matching, you can just proceed to the second option. Now in the second option we have I + 1 and plus J into 3.
So again we will do the same thing. We will try to first calculate uh the uh 0 comma 0 element. So in that case I and J will have value zero and if we try to evaluate it what we will get one >> one. So that is correct. So let's try to move to Z comma 1 that is this position.
So for that what we will get four we will get four yeah we'll get four right because I is zero and J is 1. So uh 1 into 3 is three and then we are adding one. So we are getting four that is fine. Then let's try to evaluate uh this position.
So again that position is also coming as seven because J is 2. So 2 into 3 is six and we are then adding one. So that is seven. So the first row is matching.
Let's try to evaluate this element.
So for that uh we will do I is equal to 1 and J is zero. So if we again try to evaluate it we are getting two right because this this part will become zero because J is zero and then this part will become 1 + 1 that is two. So two we are getting. Now what about the central element of the matrix?
That is also correct right because J into 3 that is 1 into 3 is uh 3 and then we have 1 + 1 that is 2. So 2 + 3 is 5.
Now we can evaluate this one as well and then other three as well. Okay. So this option is looking correct to me.
Is this correct or incorrect?
>> So order of I and J >> is different. Yeah.
So order of I and J is different. So over here what I is representing?
Is it representing a row or a column?
I think column >> I is representing column here and J is representing row here. Okay. So this pattern is correct but the position of I and J are incorrect. Okay. So now we can again try to evaluate this part. The pattern is looking similar to the previous one. But if you see this option and this option, they are the same, right?
We have just uh uh changed uh the variable I to J. So if you see uh wherever we were using I in this one we are using J in this one and uh J was J is replaced with I. Right? So this is again both the options are same and both are incorrect. Now if we see this option this option is doing the correct thing because the pattern is correct that we just evaluated. Then we have J as the column. So J is in our column and then we have I which is our row. So option D it is the correct option. Any doubt in this one?
>> So in the second option we were like thinking wrong that 14 we are getting 147 correctly. It was not right. We are getting 147 as column.
>> Yeah correct.
Okay.
>> Like so this is like inside is column and outside is row right sir.
>> Yeah. Inside is internal one is column and uh your outside one is row.
>> Okay sir.
>> See uh when we try to expand this part how we expand it? So let me try to expand this part. So how we will do that? So we will say for J in range three. Okay. So this will be our J. Then we will say for I in range three. Okay. And then we will do whatever we want to do. Okay. Print something or do whatever operation we want to do. Now if you see this J this will represent what? Row.
Right? In a matrix this will represent a row. and then the internal one will represent column.
This format you have to uh keep in mind and again this format as well you have to keep in mind that uh the outside one represents the row and internal one represents the one. Okay.
Now we'll move to the next question.
Again this one is again an MCQ and we have some code snippet and we have to find the output. Okay, what will be printed?
So we are given a data and uh we are given some updates and then we have uh a function which we are calling and we are passing the records that is this data and the updates we want to make in the record. So we need to check the logic inside uh the function. What will happen uh to the data that we are passing that is record how is it changing based on the updates and based on that we will pick the correct option.
So let's try to evaluate this. Okay. So what we will get? So first in this line we are just picking the key and value from the updates dictionary that is this dictionary.
So the key will be a b c and d in different iterations we will get a b c and d and uh in the corresponding iteration like uh when we are getting the key as a we'll get this as the value when we are getting b we will get this as the value. Okay. Now we are saying if records if key in records then we are just checking whether uh the key that we picked from updates is uh present in data or the records dictionary or not.
So for a it is present. So this part is evaluating as true. Then we are checking one another condition which is uh is instance of dict or not. So we are for this particular key we are checking its value. This part will give the value.
This part will give the value of the key and uh once we get that we are checking the data type of this. So the data type is dict in this case. So this is fine.
Now we are doing this for sub key sub value in value dot items. Now we are moving internally.
So sub key will become x and sub value will become 10. Right? In the first iteration then we are checking this part if sub key in records keys. So we are checking this x is present in records key or not. So records of key.
So this part again we are checking whether it's sub sub key that is x is present in this particular dictionary or not. Okay. If it is present then we will do some other operation. If it's not we will do some other operations. If it's present we are adding the sub value. Okay. We are just adding that value. And if it is not present we are assigning that value. So in this we have uh 10 present and from here we are passing five again. So the value of x will get updated right what will it become?
We already had 10 and now we are in the updates we are passing 10. So will it update >> 15?
>> Yeah, it will update. It will be updated and we will get 50. Now why? What about Y?
Y won't be updated, right?
>> No, it will remain >> because uh in this we are not passing any value for Y. So Y will remain the same.
And what about Jed?
it will be added because it was not.
>> Yeah. So this condition will be uh evaluated and we will add jet. Okay.
So for a we'll get x = 15, y = 20 and z is equal to 5. Then we will move to b.
Okay. So we will do the same thing. So for B X will become will be five Y we will add Y will become 10 and zed we already have so zed will remain the same. Then we will do the same thing for C. Okay.
What will happen to C?
So 100 will be replaced by x is = 10 with that dictionary.
>> Why do you think so?
So because if uh it is checking the updates one if the key like sub val it if it is a dictionary then it is doing this and the update in update C is a diction has a dictionary >> right?
>> So it will update uh the data part to the new part it will replace it with the new one. Okay, >> because it like if it was already present it would have added but it is not present so it will be replaced.
>> So in this line we are basically checking whether key is present in records or not. So it is present. First thing is C we are checking C is present in data or not. It is present. Okay.
Then we are evaluating this part. Okay.
Whether records key is checked or not.
So records key is what?
Records is this right? We are passing data as records and uh records of key key has current value three. So sorry C not three. So we are checking data of C and it is 100 and its data type is not dictionary. So this particular thing is not evaluating to true. So we won't run this part and we'll directly move to else part. And in the else block we are saying records of key is equal to value.
Okay. So records of key is again what currently it is this. But now we are assigning this value. So when we assign this value is coming from where value is coming from your updates dictionary. So that is why 100 will be replaced by this particular. Okay.
Now what about D.
So D will also be added because it is not here. So it will be added in records.
>> Yeah. So D we will again add. So how we are adding D? Because we are just uh evaluating this condition again. And in this condition we have uh two sub conditions this one and this one. If you check this particular condition key in records that is false right? Because key is currently D and D is not present in records. So that is false. So that's why we again move to the else block and we will run it and we will add D into records.
So option A this one seems correct.
Any doubt in this one check the other options. Yeah.
Is instance is instance is basically checking the type of this thing. Okay, if you maybe say is instance of this. Okay. So it will first uh uh check this and then this. The second uh parameter is your data type and first is uh your data and it will return a true or false. Okay. So 7 is indeed uh integer type. So it is returning true.
Now if we use 4.5 maybe it is returning false. Okay. So it's just checking the data type of uh your data.
>> Yes sir. Got it. Thank you sir.
>> Yeah.
So option A seems correct here.
Any doubt in this one?
Okay, let's move to the next question.
So again we are we have two functions here.
Okay.
So these are the two functions that we have and uh we currently have a list nums and we are doing some operations based on the two functions that we have and then we are printing the value. So let's try to see what uh we are doing using the functions. So the main function that we are calling at the top level is safe get square. Okay.
Now in safe get square we have try and two accept blocks return get squared items comma I. Okay. So we will try to execute this. If it gets executed and uh we don't find any error then we will return the result from this function. If we find any error like index error or some other type of exception if we find we are catching it and uh uh in case of index error we are returning zero. In case of any other error we are returning minus 5. Now we need to check what this function is doing and based on this we will just evaluate our uh code as so first of all items is what items is a list right and uh we are squaring the uh I is any index like we can pass any index uh from this nums list and uh then we are doing nums of i and uh we are squaring the value.
So for this what do you think what uh will be printed -1 0 or some other value.
So we'll get four.
>> We will get four. Why?
>> The index is one here. So -2 will be taken and -2² will.
>> Okay. So we uh we are calling this function and uh I items of I is giving minus2 and we are just squaring that value and printing it. So the first line will print four. What about the second line?
>> So nine.
>> So it will print nine. Why? Because uh minus one will give us three and we are just uh squaring it. So we are getting okay. What about the third uh line sir?
>> Zero.
>> Zero. Why?
>> Because the list is empty and last index is uh empty sir.
>> Okay.
So do you think this line will be executed?
>> Yes sir.
>> Okay.
So in case of uh empty list we are trying to access uh the minus one element and that is not present. So we will raise uh index error but in the function we are catching that error and uh we are returning zero. So that's why we will get zero.
What about the last one?
So minus one because it will be an error but it is not an index error. So we will return minus one.
>> Yeah. So we will return minus one.
So option this one seems correct. Option D.
>> Yes sir.
>> Okay.
Let's move to the next question.
This is an MSQ. So, we may have multiple correct options. Let's try to evaluate all the options.
Okay. What do you think what uh okay it's talking about uh the prints only. So, let's see what we are printing. What will this print?
So 3 4 5 >> 3 4 5.
So T3 is basically the combination of uh these two tpples and then we are saying 2 to 5. So 2 is three then four.
Do you think five will also be there?
>> Yes sir. Because it will go from 2 3 4.
It will not go till five but till four.
So >> index four I mean.
>> Yeah correct. So it will pick three four and five. What about uh this one? length of T4 s two.
>> Why?
>> Because T4 is the tuple of tpples T1 and T2.
>> Yeah. So, uh nested, right?
>> Yes sir.
>> Okay. So, this option is correct. Option B is correct. Option C is also correct.
Let's see other options. So what about this one? What will this print?
>> So true.
>> True because we are just checking five is there in T2 or not and it is present.
So we'll just print true. So option four is also correct.
Okay. So, option four is also correct.
What about uh this one?
So, print t1 will return one.
Y1 because here we are trying to assign some value. So t1 of 0 is equal to 10.
We are trying to change this value and tpples are immutable right. So it will throw an error and we'll move to the accept part and in except we are saying that t1 is equal to t3 of zero. Now t3 is what t3 is combination of this and we are just picking the zeroth element.
So that is one. So that's why t1 will be zero sorry one. Any doubt?
>> So, so like hold T1 can be replaced but inside T1 we cannot replace right.
>> Yeah.
>> Okay. So >> in tuple and uh in a string they are immutable. So you can't do character or element replacement in them. Okay.
>> Okay. So >> then t1 will become one. It will not not remain a tle anymore. Right after >> yeah yeah yeah >> this.
>> Okay.
>> So option B, C and D are correct and all the other options are incorrect.
Any doubt in this one?
>> No.
>> Okay. Again, we have uh an MSQ and Okay, this looks a bit weird.
Okay.
So these are your options and uh this is just notes to understand few things okay related to the question.
So we have a file and the name is text txt and over here we are trying to open it.
We are basically opening it and we are doing some operation some write operation and then finally we are again opening that file and uh reading it and printing some stuff.
So based on this if you want you can read this as well and based on that you have to tell which options are correct.
Just to give the idea of what the f the content of the file are what's inside the file I'll just print this so that you can see it in the exam you won't get this option but uh just for convenience I'm printing this value. Okay.
So this is the content of the file that you will see inside the file. Now we are uh reading the file and printing some stuff.
Option one is it correct or incorrect?
The first line of the output is line three.
>> Yes sir.
>> It is correct.
Okay. Why do you think uh first line will be line three?
>> So because we are reading two lines and then printing the third line like print f. Five. So it will remain at line three because there are five characters there more than five.
>> Okay.
>> Correct. What about uh second option?
The second line of the output is line five.
is option B correct or incorrect.
So I think it is correct.
>> Okay.
So if that is correct that means uh option C is incorrect.
>> Yes sir.
>> Let's try to maybe run this and see what is happening.
I'll first print the first part.
Okay. Line three as we expected.
Let's try to print this part as well.
We are getting line four.
Is it correct or incorrect?
Option B.
>> So this shows it is incorrect.
>> It is correct. It is incorrect. How? See what is happening over here.
So first we did app read line. It read this. Okay. Again we did uh f dot read lines. It again read this. Then we are printing f read five. Okay. So it is reading this part till three and it is printing. Okay.
Now we are again doing f dot read line.
What will it do?
will read this line.
>> Yeah, it will remain at that line.
>> Yeah. So, it will read this line again.
And then we are doing after read 10. So, now we are here before this line. Okay.
Before this line, we are at the beginning of of this line over here, line four. And then we are printing 10 characters. So five characters are there. Then we have back slashn that is one more character. So six characters and four characters again. So that is why we are getting this particular thing. Okay.
So s that just before read the f dot read line that will only read the slashn and move to the next line I mean beginning of line four.
>> Uh repeat that again.
>> So after f do read five.
>> Yeah >> it was at three line three.
>> H >> so now that f dot read line will uh read the new line character after three.
>> Yeah. So it will move to beginning of line four.
>> Yeah.
>> Okay.
>> And now we are uh doing this. So we are printing line four and then line. This particular thing we are printing.
And then we have f.sek0.
So did you check what seek does? So the method fert moves the position of the file pointer to the given number of characters after the start of the file. So what will f do seek zero do?
>> Move to the beginning 03.
>> So it will move over here. Okay.
to the beginning of the file itself.
So the method basically uh if you read this part the method moves the position of the file pointer to the given number of characters after the start of the line. So the parameter that we are passing over here is zero. So it will from the beginning of the file it will move zero character. So zero character moving zero character means it will stay at the starting of the file at the beginning of the file. Now from there we are again printing five characters. So if we try to print that this is clear right again we are doing two times f read line and then we are again printing this part. What will this print?
The last line. What will that print?
>> Line four.
>> Line four.
Sure about that?
>> Yes, sir. because we have two red lines.
>> Okay.
>> Okay. The new line character.
>> Yeah. So, uh once we execute this, we are printing line one and the pointer is at the end of uh this line. Then when we do f read line, the new line character gets read and we move to the next line.
Then we print this and then we are printing this. Okay.
I hope this is clear. So, so every read line will read >> the current >> from the current >> from the pointer it will like it will uh try to find uh the back slashn new line character and once it reaches that it finds it uh it will just move after the new line character and stop there.
>> Okay. So like new line character means if whenever it finds new line then only it goes to the next.
>> Yeah.
>> Okay. Uh I hope this is clear.
We can check question number nine. This is uh based on class and we have to guess the output.
Okay.
So what do you think what will be the output? So we have two print statements.
So what do you think what will be printed?
what will be printed for this particular question?
So for rectangle it will print I'm a shape and the area >> 20.
>> Okay. What about uh circle >> this line >> circle plane print area not defined because >> area not defined because uh in circle class we haven't defined.
Okay.
Uh any doubt in this one?
Basically this option is true and others are false.
Any doubt in this one? If not, I'll move to the next question.
Okay.
Now question 10.
So we are printing the sum of a list and the list is getting created over here.
So over here we are creating the list and then we are printing the sum of the list.
So what will be the elements of the list?
First tell me the elements of the list and then we will try to find the sum of list.
Okay. What will be the first element of the list?
>> So 1 10.
>> Okay.
Then 10 then >> 2 and 20 >> 220 >> 330 >> M >> 440 >> That's it.
>> Yes sir.
>> Okay.
Now we are saying uh this is equal to 10 and then we are uh summing this thing. What will happen?
>> So 0 0 will also come in the beginning.
Zero Z will also come.
What do you mean by that?
>> Oh, okay.
What will be the sec? What will the second last line do?
This line. What will this do?
So 0 0 will also come because I in range five. So I will start from zero. So list will be 0 0 1 10 220 330.
>> H correct.
>> And so this line will replace three elements with 100.
>> Okay. Starting from 1 to 1 2 3 elements will be like starting from index one index 1 2 3 will be replaced by 100.
>> So the first ele the element at index one was uh zero then at index two we had one.
>> Yeah 0 1 and 10. Yeah 0 1 and 10 will be replaced by 100. Okay. So what we will get finally what will be the list?
I'm dropping the elements in the chat.
So we have this and then we are replacing the elements 0 1 and 10 and putting 100 uh there. So what will be the sum now?
155.
155.
Nope. We are getting 199.
You want to check it again?
Yes sir I missed that 449 199. Yeah.
>> Okay. So we will get 199 and uh the elements of the list are the after this operation we will have zero then comma 100 2 3 4 and 40. Okay. So these are the elements of the list and then we are summing them. So we are getting 198.
I hope this is clear.
Okay.
So now we again have an NAT.
Okay. So what will be the output of uh the given code?
We are doing some operation again on a list. It is an array and seems like it's nested array. So let's see what we will get.
So we are creating a row and the elements are calculated using this appending the row and this will form the array and then we are uh processing the array.
So first of all tell me what will be the elements of the array what we will get after executing this part.
Okay. Uh in the first row, what will be the elements in the first row?
So 1 3 >> 1 and three both.
>> Yes sir. Because I + 1 is the range.
>> Yeah.
>> When I is zero, J will go to zero and one.
>> Not one, right?
>> Okay. Okay. Okay. Yeah. Only zero.
>> Only zero. Yeah.
>> Only one. Yeah.
So this will be only one. What about the second row?
Now I is one and uh J can have value zero and one.
Two and four.
>> Two and four. Okay.
And four. Here it is. What about the next one?
36 time.
>> Okay, we are getting a pattern.
>> Yes sir.
>> So now I'll just write four date.
Sorry. 12 and then 16, right?
>> Yes, sir.
5 10 15 and 20.
>> 15 20 and 25, right?
>> 25. Yes, sir.
>> Okay, let's try to print it.
Okay, I hope this is clear.
If this is clear, now we know what is array then we have a function closest process array and we are printing whatever we are getting from that function. So what uh will be the value of total What will be the value of total at the end of the execution?
Okay. Uh what will be the value of these things? So in the first iteration what will be I and row.
Our matrix is this and I'm asking about I and row. So in the first iteration what will be the value of I in >> zero and one like first row.
>> Yeah. So I will be zero and uh first row is uh this particular thing. Okay. This list.
>> Yes sir.
>> Okay. And now we are uh trying to add uh the value that we have at zeroth index in the list. So that is one. So total will be after the execution total will become one.
>> In the next iteration we will have i is equal to 1 and row is what row is >> 2 4. So end yeah end one will be added.
>> We are adding this again. We will do the same thing. In this case we will add 9 then we will add 16 and then we will add 25. Okay. So what will be the sum?
Let's try to do this. What we will get?
1 we have 4. We have 9. We have 16. We have and 25. We have 55. Okay. So 55 will be your answer. Any doubt in this one?
Any doubt how are we getting 55 and why did we pick the last elements?
Okay, I hope this is clear. So our answer is 55.
Now again this is again NAT and uh we have a function defined over here. We are doing some operation on a dictionary and uh then we are calling the function with the dictionary and this is index I think I is with maybe index. So we are calling it and printing the value.
So this is here we are creating an empty dictionary and uh at uh like uh when the key is zero for uh key zero we are assigning the value 1 2 for key one we are assigning value 3 4 5 in list format and uh for key two we are assigning this value and then we are calling the method at index zero.
So let's see what is happening in the method.
So here what we will do we will check if I not in child keys. So child do key will give us 0 1 and two and we are checking whether I is there or not. So I is present in the dictionary. So we will not evaluate this part. We will move to this particular part and then we will evaluate. So n is equal to 1. We are initializing. Then we are doing for J in child I answer is equal to then we are calling basically this is a recursive call. So for J in child uh dicty so we will get uh two values for uh J 1 and two and uh then we over here we are adding the values okay so let's try to evaluate this now we are calling this particular ular thing procedure again and uh now we are passing the index j. So in the first iteration the first iteration of this part j will have value one. Okay. And uh when we pass J in this we will go to this particular thing where key is one and we will again check all the child of what J right that is one. We will check all the uh children and uh then we will pick the first child because uh again when we pass uh this thing when we call this we will again hit this part and this in this part we will have uh this particular thing and instead of I we will have J in that case. So okay and uh when we do child dict of J that is one we'll get this thing. So in that case we will have uh in the first iteration we will have three and again we will check whether three is there in child dect or not. It is not. So we will return one.
Okay.
So we are doing that. Is this clear or do you want me to explain it a bit more?
>> So, so answer will be one.
>> Not one.
Answer won't be one.
We haven't come to that yet. I just explained that uh uh we will basically check all the children and uh based on some operations that we are doing inside this particular method we will add some value and finally we will return answer. This is recursive call. So yeah is the recursion part clear? If not, uh, let me Okay, let me pull this up and try to explain it further.
Okay. Are you guys able to see the whiteboard that I'm presenting?
No sir.
What about now?
>> Yes sir.
>> Okay. So let me clear this part first.
Okay. So initially what is the value of I? I is uh zero right from here we have passed zero.
>> Yes sir.
>> Okay. So Initially we have passed zero.
I'm using touchpad so I might write something weird. So try to e and understand. Okay. uh then over here we are checking whether I is present in child dict or not okay so for zero it is present right >> yes sir >> so this condition won't be evaluated we will directly move to this part okay now we are saying answer is equal to 1 and then we are doing this part okay so J will have two values What? Two values >> one and two.
>> One and two. Okay.
Now over here we are again calling this function. Okay. And uh we are calling it with the value of J. So in the first iteration J will have value of one.
>> J will have this value. Okay.
And uh we again called this method and uh now we passed uh one as the second parameter. So again this particular thing will be executed. Now we will again try to see we will again try to execute this part and uh we will see whether one is present in child or not.
Right?
It is again present. So return one won't be executed. We will again move to this part. Is this clear?
>> Yes sir.
>> Okay. So now we are again executing. And now we are executing for one.
Now we'll again try to execute this. And it is again saying child dict of I. So currently since we passed one over here so I is one basically and uh we'll check all the children of I.
So that is 3 4 and five.
Any doubt in this part how we are getting 3 4 and five?
>> No sir.
Yeah. So we got these three this is fine and >> yeah then we are again calling this part and uh we are picking the first value so that is three we are picking this value again calling the function and uh then we are executing this part.
So when we try to execute this part so first we will evaluate if I not in child dict keys or not. Okay. So we will evaluate that and that is true right for three that is true because >> child dick has only three keys and they are 0 1 and two three is not present. So we are getting true. So in this case we will return one right >> one. Yes sir. So answer was one initially we initialized it to one and because of three this particular thing again returned one. So answer become became two right?
1 + 1.
Now three is done. So let me remove this. Three is done. Now we will move to the next child. The next chain. So four again. Four is again not present. Remove this. So answer became three. Right?
Five is also not present. Five we also crossed.
Answer became four. Right?
Now one is done because uh one had uh one had uh three children and we executed for all of them. So one is completed. Now we will move to two.
Okay.
So, two has three values. 6, 7, and 8.
We'll do two and two has 6, 7, and 8.
We'll evaluate six first.
Six is not present. Again, one will be added to answer. So answer is basically 2 3 4 and five and uh then we will do seven. Seven is also not present again one will be added. So we have six eight we will do because of eight we will again add one.
So we have seven now right?
Then two is done.
Any doubt till here or is it clear?
>> Yeah, it is clear.
>> Okay.
So for this one we are getting how many?
1 2 3 crossed 1 2 3 4 5 6 and these two eight and answer was already initialized to one. So eight we encountered over here and one was already there. So total nine values we encounter. So answer will become at the end of the execution answer will become nine. Right?
>> Yes sir. Any doubt in this part?
Okay.
Let's move to next question.
Again this is uh again a numeric type question and related to class.
We are printing one value over here and we have to find uh the output that is this print value itself.
So what will be printed?
Anyone?
What will be printed?
This one is not very hard.
Okay.
Uh see this. So we are initializing an object of class uh B okay and then we are calling this function. So first we need to see uh what this function is doing and uh for that we need to evaluate uh the class uh B. Okay.
So if you see here we are uh calling this function uh calling uh this and inside that we are calling the init method. So super is basically what super is the super class.
So we are initializing this class and uh inside that we have the init method we are calling that. So because of that we will have self dot value is equal to five. Okay. So B will have self dot value is equal to five.
Now we are doing this. So what will be the value of self dot sorry yeah uh what will be the value of self dot value after this we are multiplying by two and when we initialize we had uh five so 10 right the value of self dot value is 10 now and then so after the initialization that will be your state and then you are calling this function object dot add three this part.
So over here again we are doing super and then we are doing dot add num to two. What will this do? What will this particular uh part do?
What will happen again? We are doing the same thing what we did over here. Okay, same thing.
So we have add method defined in the super class. So we are using that and we are calling that add method and we are passing num into two. So what is num?
Num is three. So 3 into 2 is six. So we are calling this particular method and the the parameter that we are passing is six and inside that we are doing self dot value plus num. Okay. So num is six and self dot value we just calculated because of this it was 10 right five we initialized with and then we multiplied by two so 10 and then we once we evaluate this particular thing so 10 and uh n into 2 is six so we'll get 16 is it clear how We are getting 16.
Any doubt in this one?
Okay.
So I hope this is clear.
Let's move to next question.
Question 14 is uh comprehension and it has two parts. So let's try to see what we have in the comprehension part and then we'll see the question. Okay.
So we have a file name, number of lines, seek position, override position and override text.
We are calling a function create and write file which is this number of lines from here we are passing and let me try to show what we are getting.
Okay, this is the file that we are putting. Okay, because of this particular thing and number of lines we passed, we are getting six lines and uh the lines are the line one to this kind of format we have followed.
Okay. And then we have another method override some text and uh it is accepting a file name that is this only. Then overrite position we are passing 21 and then overrite text we are passing and based on that it is overwriting something and then we are uh writing that thing.
So let's see what is happening over here. This is the logic that we need to figure out and after that we can answer the question.
What will this do?
So we used uh the seek method uh just now few questions >> 21st see character.
>> Yeah. So 21st character from this beginning. So we need to count the characters. So 4 5 6 and then we have uh the back slash n that is seven. So first line has seven characters. Second also has seven. Third also has seven. So that is 21.
So whatever we will do it will appear over here. Okay.
Now we are doing original is equal to after read line.
What will this do?
original will become line 4/ line 4/ we are doing uh yeah line for/x again we are doing the same thing app f seek override position what will this do >> line it will go to line seven >> line seven it will go to line seven.
Okay. And then we are saying f dot write text back slash n text is what text is overrite text that uh is this one. So in line seven you are saying we will add uh this particular text right this particular thing we will add.
Correct?
>> Yes sir.
Okay, let's try to run this. See what's happen.
We are getting this.
Why are we getting this?
So whenever we call f seek it is starts from the beginning. Okay this was written right in this particular thing.
So whenever you will call do seek method it will always start from the beginning of the file and it will move n character. So n is whatever you are passing as the parameter. So we are again passing over right position. So this uh for this the pointer move to the beginning of line four. Okay.
For this also it will move to line four only. This beginning of line four and then we are writing this particular thing.
Okay. Any doubt in this one?
So sir why line five was modified line five we will come to that but uh is this part clear or uh >> yes sir this is >> okay so if this part is clear let me close this redone this okay we are getting the same Now I'll come to that part. Okay. Let's first try to see what uh is uh 14.1 file.
How many number of lines will be there in the file example file dot text?
We are seeing how many lines? Five lines. Right? Six. the sixth line you don't need to count. So five lines are there and uh whenever we use Python to write files it generally adds backslash and at the end so we don't uh count that line.
So five lines are okay. Okay. So we have five lines.
Any doubt in this one? I have uh shown the output as well. So it should be clear that we will get five lines.
Now we have what will be printed if we call random access read this immediately after running the given code. Let's try to see this what we are getting.
Okay. So in this what we are doing we are first uh reading the file. So in the first line we are reading the file then we are saying f read five. F dot read five we are storing in first character.
F dot read five is this part line and space.
Then we are doing f see seek position.
Seek position is 10.
Right?
So we move to 4 5 6 7 8 9 10.
We'll move forward here.
Then we are doing line is equal to f dot read line. So it will complete this line and move to this line line number three. Then we are doing rest is equal to f dot lines. So f dotl lines we are doing. So all these things will be stored in rest in a list format and then we are just printing the lines. So first line will be this. Then we will get this as the second line and then this will be our third line.
Any doubt in this one?
Okay. Uh now coming back to the question why we are just uh getting this part. Okay. So I think till here everything is clear. The confusion is why like previously we had few more lines.
until line six was there. Then we ran this part and the file content changed.
So if you see what does this mean? R plus anyone.
What does R + mean?
Read plus write that is true.
Over here when we are calling F.Right Right.
>> It is reading the file and writing also.
>> Yeah. Both things.
So when we are calling this f.right text, it will replace the content. Right?
Is this clear? It will replace.
>> Yes sir.
>> Okay. Now because of this part where is our personing of line four.
>> Beginning of line four and then we are writing.
>> Yes sir.
>> We are writing what?
>> Overwritten text.
Yeah.
So that we are writing and because of that we are getting this content and uh the later parts are getting removed.
Is this clear?
>> No sir sir why those are getting removed because we are replacing that line only.
No >> this line.
>> Yes sir. Line four we are replacing. Why line five is getting affected?
>> So we are doing g right now >> when we let me show it replaces the character count.
What character count >> from line four to the n in line five?
You're replacing 16 characters, >> right?
Okay. Okay. Understood.
>> Is this clear?
>> Yes sir.
>> Okay.
So if this is clear I hope uh question number which we did this we already did and uh this I already showed you. So what was it printing these three things right?
>> Yes.
>> Okay. So option this one option B >> yes >> okay any doubt in the previous question number 14 okay let's move to question 15 then again this is uh a comprehension based question we have a code snippet given over here and based on that we have some questions. So let's see what is happening over here.
So we have a method defined and inside that method we are calling that method basically and uh we are passing a list to that method and inside that method what we are doing we are saying categories is equal to dictionary and uh it has three keys and uh currently all the three keys are mapped to empty sets and we have one function over here and we are doing the iteration over here for num in nums. If num is divided by two, num is uh uh num is basically uh an even number.
If it is an even number, we are adding it to category 1. Okay?
Else we are adding it to category two.
If check num then we are adding it to category three and check num is doing basically this thing whether uh num is divisible by five or not. So if it is divisible by two we are adding to uh one category one. If it's not divisible that is odd number we are adding to uh category 2 and category 3 only when any number is divisible by five. Is this clear?
>> Yes.
>> Okay. So what will be the value of the following expression after running the given code snippet sorted result this and this what will be the result for this one we have some options let's see that as well what What is the type of uh this uh result category one? What is the type of this divisible by type? I'm asking what is the type of uh result category one >> a set >> it's a set right >> it's set >> both are set >> yes >> and we are doing and operation so in set what does and operation do >> intersection >> intersection so what we are basically saying that we want the intersection of this and this set correct.
So >> yes, >> what will be the value?
>> 10.
>> Only 10.
>> Yes, only 10.
>> Yes.
>> Yeah. So because uh category 1 is just storing even numbers and uh category 3 is storing dividal five. So we will just get 10 as the common.
>> Okay. What about uh this one?
What is this pipe operator >> or pipe is or okay.
So what will happen? What we will get?
Union pipe is union. Okay.
So what will be the value of the expression it's asking for length >> n.
How >> what are you have 10?
>> Okay. So we will have 10 values.
So what are the values in category 1?
>> 2 4 6 8 10.
>> Okay. And uh category 2 >> 3 57 9 >> 3 5 7 9 All the even numbers are in category one and odd are in two. And what about uh category three? Five and 10, right?
>> Yeah.
>> So what's the total if we add all of them?
>> Nine.
That's union.
So uh yeah we have to do the union. So that will be nine. Okay.
Any doubt in this one?
15.2 two.
Okay.
So again 15.3 is an MSQ and if result is equal to this which of the following expressions will be evaluated as true.
So first option is it correct or false?
Correct.
>> It's correct because category one is storing even from this list. Category 2 is storing odds and category 3 is storing the uh the numbers that are zero five.
What about this one?
This is false.
>> Sure.
>> It is only one.
No. No. Wait.
>> 10 and 20.
>> It is true.
>> It is correct. Right. This is correct.
>> This one is This one is false or true?
>> False.
>> False. Okay. And what about this one?
This is also false. Why? Because these all these numbers are unique and we are just creating three categories and all numbers are getting distributed in these three categories itself. So if we do the union operation we will again get this whole thing right.
So this is again false. So sorry we have and operation. Yeah and operation. Okay we have and operation over here. So no that is not true.
So if we do result of category one and uh category two what we will get for this part >> empty set >> empty set empty set correct and uh because of this we will get just uh category three and category 3 is this one. Okay so last one is also correct.
>> Yeah.
>> So option A, B and D they are correct.
Okay, so that's pretty much it in this set. Do you have any other question?
If not, I'll just close the session.
Okay.
And uh have you guys uh completed the form, submitted the form after solving the questions in them?
If not, uh please do it in next 5 minutes. I'll close the forms after that. Okay. Thank you.
>> Thank you, Sun. Yeah.
This person sounds differentiate different There you go.
Related 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











