After the completion of the Python tutorial series, we are presenting you with the Python quiz series to master and evaluate your skills and knowledge of Python in a fun manner. This is the first Python quiz, therefore, we have included basic and some intermediate level questions. So, don’t worry, if you are new to Python, it will help you to test your knowledge of basic concepts.

Q.1. How many CPUs will the threading library use? Zero. threading does not make use of CPUs. One Two All available CPUs Correct! Wrong! threading only uses a single CPU. For running code on different processors, you can use the multiprocessing library. Q.2. Which of the following codes raises an exception? #test a={1, 2, \ #comment 3, 4} a={1, 2, #comment 3, 4} Correct! Wrong! The backslash line continuation character should be the last thing in line. Q.3. Which of the following follow PEP8? Please select 2 correct answers print([2::7]) print (“Hello”) groceries = (‘milk’, ) print(“Hi”) ; print(“Hello”) scores = {'Ayushi': 97, 'Megha': 98} Correct! Wrong! There should not be space between a function’s name and its parentheses. There should not be a space after the element in a tuple with a single element. There should not be space before a semicolon. Q.4. What will this code print? 8 a+1 This code will raise an exception None of the above Correct! Wrong! This code will raise an exception because you cannot put whitespace before a statement. It raises a SyntaxError for unexpected indent. Q.5. What is the maximum value for an integer in Python 3? 2^63-1 32767 65536 No limit Correct! Wrong! There is no limit on the maximum value of an integer like in Python 2. Q.6. How do you denote the end of a block in Python 3? By indenting the next line less than the current With a semicolon } With the end keyword With a backslash \ Correct! Wrong! Since there are no curly braces in Python, indentation is mandatory Q.7. Which of these if-statements work? Please select 2 correct answers if i > 7: print(‘Hello’) if i > 7: if i 7: print(‘Hello’) else: print(‘Hi’) print(‘Hello’) if i > 7 else print(‘Hi’) Correct! Wrong! You cannot put a nested if-statement on the same line as its parent. You cannot put else on the same line as if. Q.8. In this list, how will you access the letter ‘t’ in ‘bat’? list[1, 2, 1, 2] list[2][1][2] list[1][2][1][2] list[1][2][1] Correct! Wrong! ‘t’ is at index 2 in the string at index 1 in the list at index 2 in the list at index 1. Q.9. How will you turn the list a = [1, 2, 7, 8] into [1, 2, 3, 4, 5, 6, 7, 8]? Please select 2 correct answers a[2:2] = [3, 4, 5, 6] a[2:3] = [3, 4, 5, 6, 7] a[2:2] = [3, 4, 5, 6, 7] a[2:3] = [3, 4, 5, 6] Correct! Wrong! a[2:2] adds elements between 2 and 7. a[2:3] also replaces 7. Q.10. What is the value of y? 2 5 6 This code raises an exception Correct! Wrong! Q.11. What is the result of {1, 2, 3} & {4, 5, 6}? {} set() {1, 2, 3, 4, 5, 6} None of the above Correct! Wrong! Their intersection is an empty set. {} is an empty dictionary, not an empty set. Q.12. Which statements delete the value ‘milk’ from the set s = {‘milk’, ‘cheese’, ‘butter’, ‘buttermilk’}? Please select 4 correct answers s.discard(‘milk’) del s[‘milk’] s -= ‘milk’ s -= {‘milk’} s &= {‘cheese’, ‘butter’, ‘buttermilk’} s.difference_update({‘milk’}) s.pop() Correct! Wrong! You cannot index a set. You cannot subtract a string from a set, you can subtract a set from a set. pop() will not necessarily remove ‘milk’. Q.13. In the following code, how many objects and references does Python create? One object, one reference One object, two references Two objects, one reference Two objects, two references Correct! Wrong! There is only one string object ‘Ayushi’ and two references to it. name and fname refer to this object. Q.14. According to PEP 8, what case should you use for variable names with more than one word? Camel case Pascal case Snake case Kebab case Upper case with snake case Correct! Wrong! A variable list style type should be written as list_style_type. This is snake case. Q.15. What is the output of the following code? * ** *** **** Correct! Wrong! nums is [[], [0], [0, 1]]. We print a star for each value in each sublist if the value is less than 2.

This was all in the Python quiz by DataFlair. How many questions did you get correct? Share your experience and score of the Python quiz in the comments. If you didn’t score well, no need to worry just revise the concepts from the sidebar in which you are lacking.