Can You Answer These Tricky Python Questions?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello everybody and welcome to another video where i embarrass myself by trying to answer python quizzes in the first video for this i thought this was going to be a breeze this was going to be very easy and simple but it turns out the questions and the quizzes i found are actually very challenging and there's a lot of really strange and obscure questions in there i'm not necessarily complaining just stating that they have some really kind of weird things in the quiz that i wouldn't have expected that i haven't actually seen in python before with that said hopefully you guys are looking forward to watching me try to do this as always please follow along let me know how you guys do in the comments down below and maybe it will make me feel better if i fail any of these quizzes with that said i do of course need to give you a quiz if you watched the last video you'd know what this is but the question that i'm going to ask you is what is the sponsor of this video and you need to watch the next minute to find that out before we get started i need to thank lenode for sponsoring this video i've been using and working with lenode for nearly three years now and they've consistently been my go-to choice for hosting my applications and servers in fact right now i'm using lenod to host the official tech with tim discord bot a website multiple of my domains and a kubernetes cluster lenode makes it super easy to spin up servers with their one-click app marketplace and have tons of written guides and youtube videos on their channel to help you get started now if you're having any issues you can reach out to the 24 7 support team and actually talk with a real human being now lenode's pricing is simple with no hidden fees and full transparency and you can test out lenode services for free by using the link in the description and claiming a 100 60 day credit for any new accounts it's been an absolute pleasure to work with lenode over the past few years and one last thank you to them for sponsoring this video alright so let's dive in here there's a bunch of quizzes they are a lot harder than they look i'm probably gonna get a bunch of questions wrong but uh i was thinking we would do the python lists and tuples so let's do this one this question or this quiz contains 11 questions let's start this up uh and let's see how hard this one is okay which of the following are true of python lists all elements in the list must be the same type not true there's no conceptual limit to the size of a list i don't think there is so i'm going to check that but yeah i don't think there's any limit to a to a list although there must be some limit but i guess that's based on your computer a list may contain any type of object except another list false it can contain a list a given object may appear more than once in a list okay and these represent the same list no they don't okay so there we go that was an easy one to start uh assume the following list definitions several short rebel sessions are shown below which displays the correct output okay so a colon is a uh no that's not true that would be false because this is a copy so it won't be the same object the max of a from two to four plus gralt okay two to four is this to this because you don't include the last one so baz and klux and then we're adding something that starts with the g the max is going to be a q when you're doing uh character equivalence here so i think that's correct uh we have a at four and then stepping by negative two so let's go here so zero one two three four so start here step negative two get that step negative two get that so that is gonna be quack spazz foo wherever you say that that looks correct to me uh a at negative six list index out of range let's see negative one negative two negative three negative four negative five maybe six all right so no that's not going to be correct because uh this will actually work a negative six should give you foo right but it's saying it's gonna be index out of range okay and then print a negative five to negative three so negative five is negative one negative two and a three and a four negative five okay and then you're going to negative three which is here so you should just get bar and baz which is what you get and do we get this correct nice okay next question all right so consider the following nested list definition what is the expression that returns the zed in baz okay so we're going to need a bunch of indexes here let's just start this so that's x this list is at index one so we go one then we have this list which is at index two okay and then we have this which is index one and then we need the last character which is i mean i can just use negative one or i can use one uh let's go negative one and be actually sorry negative two and be fancy and see if that gives it to us is actually telling me that's wrong okay well that would work if we did negative two i don't think i'm crazy one two one negative two oh sorry it's negative one i want the last character oh my gosh i'm an idiot uh okay well let's go on to the next question i yeah i guess i deserve that for trying to do that okay what expression returns the list bar 2.718 so we need a slice here so let's try this that's going to be again x1 x2 x1 or no that would access baz so now we have this list then we get this list now we just want the last two so let's go with one colon and there we go okay nice all right select all the following statements i remove the middle element three from a so that equals one two four five okay so this is not gonna do it a two colon three equals an empty list so two colon three would be this not including that so it's essentially just this equals an empty list um i don't know if that's gonna work i know remove will work i think that will work but it's either this one or this one it's one of these two i have to check and then del a2 will work so a23 so if we have 2 3 we're at this going to this but not including it so it's just this and you're setting it to an empty list but i think since it's a slice that works i think if you do a 2 colon 2 then that's not going to do anything because yeah that seems like that's not going to do anything when you make that an empty list okay let's try this and okay miracle i i really am forgetting what this two colon two does uh when you have like the same index on both sides but let's see if there's another question like that okay so list a is defined as follows which of the following statements adds d and e to the end of a so that it equals a b c d e okay so extend will work to add d e um a at len a colon so that's the last index of a i think that's valid to use in a slice but not for a normal index colon so you're extending it by d e i think that's going to work appending that will not work because it's a list so that will actually add the list inside of this list giving you a nested list uh adding a list will work uh a negative one colon equals d e uh negative one i think would start here and replace that so i don't think that works and then a plus d e um this is tricky because i don't know if plus equals d e i think that will be treated as an iterable in python which means it would actually add each individual element because when you're doing for example plus equals here with de it's extending i think that works um yeah i think that works i think that treats it as a list or that's just an exception or you can't do that at all uh let's try this shocking okay we got it correct next question all right write a python statement using the slice assignment that will fill in the missing values so a equals one two three four five six seven eight okay so we saw previously that to remove an element we could use whatever the index of that element is colon the next index and then that essentially replaced it with whatever we put so i think i can use that same thing here to do something like a colon and then i believe this is gonna be two colon three same thing we want the middle element here right and if i do two three i'm accessing this and i'm going to replace that with something so i think i need to make sure that i include my 7 and what i replace this with unless i can do something like 2 colon 2 and that would insert after element 2. um i think i'm going to go safe here and do 2 colon 3 and then just make this 3 4 5 6 7 like that and then the 8 will be in there because i think it will remove the 7 when i do that again i think i could do though a two a colon a two colon two let's try this one see if that works uh three four five six coach should include a slice assignment did i not do that would this not work does that not give me the correct result i think what i did works um okay i guess it's saying though i only could use three four five six so i guess i should have done the other way but i think that this works someone can tell me in the comments i guess but i'm pretty sure that that's correct okay next question uh suppose you have the following tuple definition t equals foobar baz which the following statements replaces the second element bar with the string q-u-x it's a trick question tuples can't be modified i actually think that's correct because you can't do index assignment for tuples so yeah let's do that boom trick question got it next all right write python code to create a tuple with a single element uh the string foo and assign it to a variable called t okay t is equal to and then there's multiple ways to do this but i think i can just go foo like that tuple with single element i need to make sure i include the comma that's probably why they have this question because if you just wrap it in parenthesis it will just like evaluate the parenthesis and give you foo but if you do the comma then it will be a tuple i also think you could just do this and that would work too but let's run that and there we go nice all right next question uh consider the assignment statement abc equals oh gosh okay uh following the execution of the statement what is the value of b okay so we have to go through the steps here on this and figure out what this is so a is gonna be two and then we need to step by three so one two three so that's five i think it's going to be five because this will give us a slice containing two five and eight so i think five is correct and there we go all right we're doing well on this one next question assume x and y are signed as follows okay um what is the effect on this statement oh my gosh oh this is just a slice with y x x y equals y x quant negative one that flips it so it should just they should be the same whenever you do conquer negative one you're just going to reverse this so if you have y x you're going to get x y so x is going to be able to x and y is going to be equal to y meaning they should just be the same so 5 and negative 5 uh they're unchanged boom okay complete quiz and how many did we get wrong we got two questions wrong and one of them i think like we got correct so pretty good i'm going to call that 91 percent not 81 percent uh and i think i probably have enough time to do one more so let me go back to the home page there maybe i'll find a short one and then we'll go from there all right so i found a short one but i don't know if it's going to take us less time because it is threading which is a lot more complicated but let's try this at six questions um let's just let's give this one a shot again this will probably be much more complicated than the other ones so what does threading dot lock do uh no it does not shift to all caps synchronize threads allow only one thread at a time to access a resource um that's that's pretty well what the lock is meant for so oh i it's okay i thought that was just multiple choice synchronized threads as well okay uh that's fine uh how many cpus or cores will the python threading library take advantage of simultaneously the answer is one yes unfortunately there's a global interpreter lock in python meaning you can only use one core of your cpu uh even if you have like a 12 core cpu or something ridiculous like that okay what does the thread.join method do thread.join i think that means you're waiting for this thread to finish wait for the thread to finish yes okay nice not so hard now race conditions are not something you should add to your code two threads incorrectly accessing a shared resource the weather on a race day testing which thread completes first uh i think it's this one nice okay this is actually surprisingly easier than the other one why is a good idea to use the thread pool executor as a context manager when you can i passed exceptions back to the main program it manages the startup of all threads and waits for them all to complete it looks better it prevents threads from having race conditions i don't think it would prevent race conditions the exceptions are actually interesting i've never used the thread pull executor so i'm essentially guessing between the first two here it manages the startup of all threads and waits for them all to complete i don't know if it would do that um thread pool executor you have a pool of threads i don't know i my feeling is this one but it could be the exception too so let's try this and there you go okay all right now we're almost done here true or false once you start a threading dot timer you cannot stop it until it expires again i've never used this before so i have no idea i'm going to imagine that the threading dot timer it's just a timer i'm going to imagine you can't stop it but if an exception occurred that would stop it right um let's go with true and it's false okay of course you can stop it with cancel all right and a nice four out of six sixty-six percent all right guys i think with that i am going to wrap up the video here again let me know what you think of these quizzes honestly they're pretty easy for me to film and i've been feeling a bit ill recently so i'm trying to get some easier videos out for you um anyways i think they're interesting definitely very challenging i'm learning some stuff from them and hopefully you guys are as well with that said if you enjoyed the video make sure to leave a like subscribe to the channel i will see you in the next one [Music]
Info
Channel: Tech With Tim
Views: 24,413
Rating: undefined out of 5
Keywords: tech with tim, python programming, python quiz, python quiz code, coding quiz, python decorators, python quiz questions, python test questions, python test online, python tutorial, python class, best python tutorial, python, learn python, advanced python test, learning python, basic data types in python, python terminology, python specifics, python language essentials, tech with tim coding quiz, python lists and tuples, python threading, linode
Id: NvBoFER9Y1Y
Channel Id: undefined
Length: 13min 59sec (839 seconds)
Published: Tue Jul 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.