Python MCQ (Multiple Choice Questions)

Python MCQ

1) Choose the right pair of option from given following for who developed Python and which year Python is developed?

  1. Bjarne Stroustrup, 1979
  2. James Gosling, 1995
  3. Jim van Rossum, 1987
  4. Guido van Rossum, 1991
Answer: d. Guido van Rossum, 1991 Explanation: Python was developed by Guido van Rossum and it is first released in the year1991, February 21 at Cetrum Wiskunde & Informatica (CWI) which is present in the Netherlands. Therefore, Option D is the right answer.

2) Which is the following statement is incorrect regrading data types present in Python language?

  1. Python have major 5 data types.
  2. Python tuples are sub data type of sequence data type.
  3. Complex numbers are not a sub data type form in Python data types.
  4. Integer value are stored as integer class type which is a sub data type of Numeric data type.
Answer: c. Complex numbers are not a sub data type form in Python data types. Explanation: Python have major 5 data types i.e., Numeric, Dictionary, Boolean, Sequence type and Set. Further Numeric and Sequence data type have sub data type forms i.e., Integer, Float & Complex Numbers for Numeric data type and Tuple, String & List for Sequence data type. Therefore, Option C is incorrect statement and it is the right answer.

3) Which one of the following is not a Python keyword?

  1. except
  2. finally
  3. calender
  4. return
Answer: c. calender Explanation: Except for 'calender' all other three i.e., 'except', 'finally' and 'return' are reserve keywords in Python and we cannot use them to define variable in our program. Therefore, Option C is the right answer.

4) Which is the following is an Arithmetic operator in Python?

  1. // (floor division) operator
  2. & (binary and) operator
  3. ~ (navigation) operator
  4. >> (right shift) operator
Answer: a. // (floor division) operator Explanation: The. // (floor division) is a type of arithmetic operator in Python. All other three options are types of bitwise operator in Python. Therefore, Option A is the right answer.

5) Which one of the following is the correct statement regarding comments in Python?

  1. Python provides us a way through which can do both single line and multiple lines in our program.
  2. Python comments will affect the print statement present in program at some extent.
  3. To apply comment we have to use '#' keyword at starting while writing a comment in our program.
  4. To apply comment we have to use '#' keyword both at starting and ending while writing a comment in our program.
Answer: c. To apply comment, we have to use '#' keyword at starting while writing a comment in our program. Explanation: Whenever we will use comments in our Python program, we have to use '#' only at the starting of the comment that will indicate to Python that this line is a comment and Python will not interpret it. Hence, Option C is the right answer.

6) Which of the following is not an advantage of defining function in our Python program?

  1. We can track a large Python program very easily when the given program is splitted into multiple functions inside the code.
  2. Python functions are not reusable and hence we have to define them again and again while using it.
  3. When we use functions in our Python program, we can avoid writing the same logic again and again and call the function every time.
  4. We can call a function many times inside the program and we can call it wherever we want inside the function.
Answer: b. Python functions are not reusable and hence we have to define them again and again while using it. Explanation: The biggest achievement of defining a function in our Python program is the reusability of the function. We can use the function many times in the program and it will imply the same logic every time we call it. That's why defining a function in our Python program saves a lot of time. Hence, Option(B) is the right answer.

7) Look at the following Python program:

given_number = 24
if given_number==10:  
  print("The given number is equals to 10 define in the condition")  
elif given_number==20:  
  print("The given number is equal to 20 define in the condition");  
elif given_number==30:  
  print("The given number is equal to 30 define in the condition");  
else:  
  print("The given number is not equal to any of 10, 20 or 30 define in the condition");
What will be the output of the above program?
  1. 10
  2. 30
  3. not equal to any of 10, 20 or 30
  4. 20
Answer: c. the given number is not equal to any of 10, 20 or 30 define in the condition Explanation: In the above code, we have defined a number 24. When Python loops through the condition, it will check if any of the define condition satisfied from elif statement otherwise it will print what's defined in the else statement. In this program, since given number is not equal to any of 10, 20 or 30 it will not satisfy any condition and print what's defined in the else statement. Hence, Option(C) is correct answer.

8) Look at the following Python program:

# three integer numbers
x = 24
y = 26
z = 31
if x>y and x>z:  
    print("The largest of the given three integer numbers is x:"x);     
if y>x and y>z:  
    print("The largest of the given three integer numbers is y:"y);      
if z>x and z>y:  
    print("The largest of the given three integer numbers is z:"z);
What will be the output of the above program?
  1. The largest of the given three integer numbers is x: 24
  2. The largest of the given three integer numbers is y: 26
  3. The largest of the given three integer numbers is z: 31
  4. Syntax Error
Answer: c. The largest of the given three integer numbers is z: 31 Explanation: In the above code, we can see that three integer numbers are defined and through the if statement we are comparing these numbers to find out which one is biggest number. So, when Python compile the code and check every condition. If the condition satisfies in first if statement then Python will print the output otherwise it will go to second if statement, similarly Python will go to third if statement in the program. Here, the condition given in if statement will satisfy and Python will print the output. Hence, Option C is the correct answer.

9) Look at the following Python program:

Marks_of_student = 57
if Marks_of_student > 80 and Marks_of_student <= 100:  
   print("Congratulations mate ! You have scored grade A in your final exams ...")
elif Marks_of_student > 60 and Marks_of_student <= 80:  
   print("Congratulations mate ! You have scored grade B in your final exams ...")
elif Marks_of_student > 40 and Marks_of_student <= 60:  
   print("You need to improve ! You have scored only grade C in your final exams ...")
else:
        print("You need to improve very hard ! You are failed in your final exams ...")
What will be the output of the above program?
  1. You need to improve very hard ! You are failed in your final exams ...
  2. Congratulations mate ! You have scored grade B in your final exams ...
  3. Congratulations mate ! You have scored grade A in your final exams ...
  4. You need to improve ! You have scored only grade C in your final exams ...
Answer: d. You need to improve ! You have scored only grade C in your final exams ... Explanation: As we can see in the above code, we have given marks of a student. In the program, elseif statement is used for grading according to the marks is given. When we run the program, Python will check every condition and in which condition the marks satisfy Python will print the output and if not, then Python will move to next condition. If none of condition is satisfied then Python will print the last statement given in program. But in this program, the third condition will satisfy and Python will print statement given with it. Hence, option D is the right answer.

10) Which of the following operation cannot be performed on a Python string?

  1. Deletion of Python String
  2. Splitting of Python String
  3. Adding elements in a Python String
  4. Reassigning of Python String
Answer: c. Adding elements in a Python String Explanation: Except for adding elements in string, we can perform all the operations given in the option. When we try to add more element in an already existing string, Python will throw an error in the output but we can complete replace or reassign the string. Hence, option C is the right answer.

11) Which string method is used to check if all the given characters in a Python string defined in our program are alphabets?

  1. isalpha()
  2. isalnum()
  3. isdigit()
  4. islower()
Answer: a. isalpha() Explanation: Whenever we need to check if the string, we have defined in our program is only contain alphabets in it, then we will use isalpha() method and place the defined string between the brackets. If the string has all the alphabets in it, it will print true in output otherwise it will false in the output. Hence, option A is the right answer.

12) Which string method is used to check if all the given characters in a Python string defined in our program are in lower case?

  1. isnumeric()
  2. islower()
  3. isdigit()
  4. islower()
Answer: b. islower() Explanation: Whenever we need to check if the string, we have defined in our program is only contain lower case alphabets in it, then we will use islower() method and place the defined string between the brackets. If the string has all the lower-case alphabets in it, it will print true in output otherwise it will false in the output. Hence, option B is the right answer.

13) Which of the following Python identifier is correctly defined as well as have highest readability?

  1. 1Nick
  2. _2_Jonas
  3. Table
  4. it_is_tablefor2
Answer: c. Table Explanation: Except for Option A (1Nick) all the other three options are correctly defined identifiers in Python but option C have highest readability among all three. Hence, Option C is the right answer.

14) Which of the following is not a token defined in Python?

  1. Keywords
  2. Comments
  3. Literals
  4. Operators
Answer: b. Comments Explanation: Python have following four types of tokens defined in it:
  1. Keywords
  2. Literals
  3. Identifiers
  4. Operators
Hence, Option B is the correct answer.

15) Look at the following Python program:

x = "Integer"
print(type(x)
When we run the above program what it will print in the output?
  1. <class 'str'>
  2. <class 'int'>
  3. <class 'float'>
  4. Syntax Error or TypeError
Answer: d. Syntax Error or TypeError Explanation: In the above program, look at the second line of code, we have not closed the print statement and only type statement is closed. Therefore, when we run the program it will show an TypeError or Syntax Error in the output. If we close the print statement in second line of code then the program will print "<class 'str'>" in the output. Hence, Option D is the right answer.

16) Which one of the following is the type of literal collections provided to us in Python?

  1. String literals
  2. Numeric literals
  3. List literals
  4. Boolean literals
Answer: c. List literals Explanation: In Python, we are provided with four types of literal collections which we can use in our program i.e., Tuple literals, Set literals, List literals and Dict literals. Hence, option C is the right answer.

17) Which of the following type of Python operator will only print True or False in output when we use it in our program?

  1. Assignment operator
  2. Membership operator
  3. Arithmetic operator
  4. Comparison operator
Answer: d. Comparison operator Explanation: Comparison operator are used to compare two numbers or identifiers defined in our Python program. It will print true in output only if the given comparison satisfies the condition otherwise it will print false in output. Hence, option D is the right answer.

18) Look at the following Python program:

Python_Set1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
Python_Set1.remove(14);
print(Python_Set1)
What will be the output when we run the above program?
  1. We cannot remove any item from the Python set after we defined it in our program.
  2. Program will be run successfully and Python will not raise an exception.
  3. 1 2 3 4 5 6 7 8 9 10 11 12
  4. Python will raise an exception and throw an error in the output of program.
Answer: d. Python will raise an exception and throw an error in the output of program. Explanation: In the above program, we can see that a set is defined with number 1 to 12 but in second line we are trying to remove element 14 from the set that is not present in the set. As per the property of remove() method, if we try to remove an element from the set that is not present in the set then it will throw an error in the output. Hence, Option D is the right answer.

19) Look at the following Python program:

Python_List1 = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23]
Python_List1.insert(29)
print(Python_List1)
What will be the output when we run the above program?
  1. 1 2 3 5 7 11 13 17 19 23
  2. 1 2 3 5 29 7 11 13 17 19 23 (element inserted randomly at any place)
  3. 1 2 3 5 7 11 13 17 19 23 29
  4. Type Error will show in the output
Answer: d. Type Error will show in the output Explanation: In the above program, an element is inserted in the pre-defined Python list in the program using the listname.insert(a,b) method. The listname.insert(a,b) method requires both argument a and b to run the method. In this method, 'a' defines the position in which the element will be added in the list and 'b' represents the element that is to be added in the list. If we don't give both arguments(a,b) while using listname.insert(a,b) method, Python will show a TypeError in the output. Hence, Option D is the right answer.

20) Look at the following Python program:

k = 24;  
while k:  
    print(k," ",end=""),
    k=k+1;  
    if k == 36:  
        break;
print("The program is now came out of while loop after running successfully");
What will be the output when we run the above Python program?
  1. The given loop is infinite loop
  2. 24 25 26 27 28 29 30 31 32 33 34 35
  3. 24 25 26 27 28 29 30 31 32 33 34 35 The program is now came out of while loop after running successfully
  4. Syntax Error
Answer: c. 24 25 26 27 28 29 30 31 32 33 34 35 The program is now came out of while loop after running successfully Explanation: In the above program, we have given k is defined equals to 24 and while loop is used on it. When k will enter in the loop, it will iterate until it reaches to 36 where it satisfies break statement. When the break statement satisfies, it will print the statement given with break and exit the loop. Hence, option C is the right answer.

21) Look at the following Python program:

Python_list = [3,4,5,6,7,8,9,10]  
count_index = 1;  
for k in Python_list:  
    if i == 8:  
            print("The given item is matched in the program")
            count_index = count_index + 1;  
            break
print("We found the given item at",count_index,"location in the given list of program");
What will be the output when we run the above program?
  1. The given item is matched in the program We found the given item at 7 location in the given list of program
  2. The given item is matched in the program We found the given item at 6 location in the given list of program
  3. The given item is matched in the program We found the given item at 3 location in the given list of program
  4. The given item is matched in the program We found the given item at 5 location in the given list of program
Answer: b. The given item is matched in the program We found the given item at 6 location in the given list of program Explanation: In the above program, a Python list is defined with a variable name count_index. A for loop is used on the list to match the given item from the list. As many times the loop continues, the value of count_index increases within the loop. Since 8 elements will match at when loop will run 6 time, the output will be item is matched at 6 location in the program. Hence, Option B is the right answer.

22) Look at the following Python program:

String_mkr = "TUTORIALANDEXAMPLE"  
for i in String_mkr:  
    if(i == 'D'):  
            continue
    print(i)
When we run the above program, which alphabet from "TUTORIALANDEXAMPLE" string from the program will not printed in the output?
  1. T
  2. R
  3. D
  4. E
Answer: c. D Explanation: As per the property of continue statement in Python, when the condition given with continue statement satisfied the continue statement will skip the loop and not print the output at particular condition and continue loop. So as in the above program, when the string "TUTORIALANDEXAMPLE" iterated through for loop and print each alphabet separately. But when iteration reach at letter D, it will satisfy the if condition and according to the property of continue statement letter D will not be printed in the output. Hence, option C is the right answer.

23) Look at the following Python program:

k = 0                     
while(k < 14):                
   k = k+2
   if(k == 10):  
      continue
When we run the above program, which of the following number will not printed in the output?
  1. 10
  2. 8
  3. 12
  4. 6
Answer: a. 10 Explanation: In the above program, we have defined an integer variable k equals to 0. We have used while loop on the variable with if condition in it. Every time the loop runs, the variable increases by 2 and prints in the output. But when k becomes 10, if condition given in the program satisfies and according the property of continue statement, the integer 10 will not be printed in the output. Hence, Option A is the right answer.

24) How Python Sets are different from those FrozenSets defined in our program?

  1. Python Sets and FrozenSet are defined very differently in a Python program.
  2. We can add items in Python sets but we cannot add items in FrozenSets.
  3. We can remove items from Python sets but we cannot remove items from FrozenSets.
  4. All of the above
Answer: d. All of the above Explanation: We can define Python sets through two methods whereas FrozenSets are defined through only one method. Python sets are mutable in nature i.e., we can perform addition, deletion etc. operations on Python sets but FrozenSets are immutable in nature i.e., no operation is performed on them. Hence, option D is the right answer.

25) Why 'pass' keyword is use in a Python program?

  1. Pass keyword is use to exit the given program.
  2. Pass keyword is use to execute nothing.
  3. Pass keyword is use to stop the execution of loop.
  4. Pass keyword is use to exit the given loop in program.
Answer: b. Pass keyword is use to execute nothing. Explanation: In Python, we use Pass keyword when we have to execute nothing from the given loop at given condition. Hence, option B is the right answer.

26) Look at the following Python program:

Python_list = [1,2,3,4,5,6,7,8,9]
for k in Python_list:   
    if(k==7):  
        pass  
        print("This is the pass block statement in program:",k)
What will be the output when we run the above program?
  1. This is the pass block statement in program: 1 2 3 4 5 6 7 8 9
  2. This is the pass block statement in program: 1 2 3 4 5 6 8 9
  3. Syntax Error or TypeError
  4. This is the pass block statement in program: 7
Answer: d. This is the pass block statement in program: 7 Explanation: In the above program, a Python list is defined and for loop is used on it for iteration of elements in the list. When the if condition defined inside the for loop at 7, the pass statement will execute and it will print the statement given in next line of code with it. Hence, option D is the right answer.

27) A Python tuple that is created without using the parentheses brackets () is called as?

  1. Tuple sampling
  2. Tuple packing
  3. Tuple sorting
  4. None of these
Answer: b. Tuple packing Explanation: In Python, a tuple that is created without using the parentheses bracket () while defining it also called as Tuple packing. Hence, option B is the right answer.

28) Which of the following is the right method through which we can create an empty tuple in our Python program?

  1. Empty_Tuple = Null
  2. Empty_Tuple =
  3. Empty_Tuple = ()
  4. Empty_Tuple = 0
Answer: c. Empty_Tuple = () Explanation: If we want to create an empty tuple in a Python program, we have to pass no argument inside the parentheses () while defining the tuple just like Empty_Tuple = (). Hence, option C is the right answer.

29) Which one of the following option is the right description for '\b' escape sequence used with a string in the Python program?

  1. '\b' escape sequence represents ASCII Backspace (BS)
  2. '\b' escape sequence represents ASCII Backline (BL)
  3. '\b' escape sequence represents ASCII Break
  4. '\b' escape sequence represents ASCII Backup
Answer: a. '\b' escape sequence represents ASCII Backspace (BS) Explanation: While working with strings in our Python program we use many escape sequences and use them in our code. The '\b' when used work as backspace function while printing the output. It deletes a space from string in print statement. Therefore, \b represents ASCII Backspace (BS) in Python strings. Hence, option A is the right answer.

30) How Python lists are different from those Python tuples?

  1. Python lists are represented by square brackets [] whereas Python tuples are represented by parentheses brackets () in our Python program.
  2. Python lists are immutable in nature whereas Python tuples are mutable in nature.
  3. Debugging a Python list is very easy as compare to a Python tuple.
  4. Python lists are more memory efficient as compared to Python tuples.
Answer: a. Python lists are represented by square brackets [] whereas Python tuples are represented by parentheses brackets () in our Python program. Explanation: Python lists are defined in a square bracket [] but Python tuples are defined in parentheses. Python lists are mutable in nature whereas Python tuples are immutable. Therefore, Python tuples are more memory efficient as compared to Python lists because of their immutable nature. And because Python tuples are immutable, they are easy to debug as compared to Python lists. Hence, option A is the right answer.

31) Which of the following is not a built-in function for Python dictionary?

  1. str(DictionaryName)
  2. len(DictionaryName)
  3. cmp(Dictionary1, Dictionary 2)
  4. DictionaryName.items()
Answer: d. DictionaryName.items() Explanation: Except for DictionaryName.items(), all other three options are built-in functions in Python available for Python dictionary whereas DictionaryName.items() is one of the built-in methods in Python available for Python dictionary.

32) What will happen when we print a Python function defined in our Python program without defining return statement inside the function?

  1. Python will show a TypeError when we run the program
  2. Python will print None in the output
  3. Python will run the program successfully without showing an error
  4. Python will show syntax error when we run the program
Answer: b. Python will print None in the output Explanation: When we define a function in our Python program without defining return statement inside the function, it will print 'None' when we use the function in the print statement.

33) Look at the following Python program:

def sum_function():  
    x = 24  
    y = 26  
    z = x+y
    z = 72  
    return z
print("The output of program is:",sum_function())
What will print in the output when we run the above Python program?
  1. The output of program is: 50
  2. The output of program is: 72
  3. Syntax Error
  4. The output of program is: 132
Answer: b. The output of program is: 72 Explanation: In the above program, when Python will interpret the lines of code, it will first assign the sum of x and y variable to z variable and in the next line of code, Python will assign 72 to variable z. So, when we call the sum_function in the print statement, it will print z as 72 in the output. Hence, option B is the right answer.

34) Look at the following Python program:

Number1 = -31
Number2 = 3.147
print(abs(Number1))
print(abs(Number2))
What will print in the output when we run the above Python program?
  1. -31 3.147
  2. Syntax Error
  3. <class'Integer'> <class'Float'>
  4. 31 3
Answer: d. 31 3 Explanation: The abs() is a built-in function class ‘Float inside Python. This function is used to get the absolute value of the variable that we have defined in our program. It will ignore all the signs and value after decimals to print the absolute value of the variable. Hence, option D is the right answer.

35) In Python file handling, what kind of access mode does 'r' represent or works when used in the syntax?

  1. The 'r' keyword used in the file opening syntax to open the given file in read-only mode.
  2. The 'r' keyword used in the file opening syntax to open the given file in read-only in binary mode.
  3. The 'r' keyword used in the file opening syntax to open the given file in read-only in append mode.
  4. The 'r' keyword used in the file opening syntax to open the given file in read and rewrite mode.
Answer: a. The 'r' keyword used in the file opening syntax to open the given file in read-only mode. Explanation: When we use the 'r' keyword with file name in Python file handling syntax, Python will open the file in read only mode. We cannot modify after the file is opened. Hence, option A is the right answer.

36) In Python file handling, what kind of access mode does 'r+' represent or works when used in the syntax?

  1. The 'r+' keyword used in the file opening syntax to open the given file in read-only mode.
  2. The 'r+' keyword used in the file opening syntax to open the given file in read-only in binary mode.
  3. The 'r+' keyword used in the file opening syntax to open the given file in read-only in append mode.
  4. The 'r+' keyword used in the file opening syntax to open the given file in both read and write mode.
Answer: d. The 'r+' keyword used in the file opening syntax to open the given file in both read and write mode. Explanation: When we use the 'r+' keyword with file name in Python file handling syntax, Python will open the file in both read and write mode. We can modify or make changes after the file is opened. Hence, option D is the right answer.

37) Look at the following Python program:

Givenfileptr = open("Givenfile.txt", "w")   
Givenfileptr.write('''''Python programming language is the modern day programming language. It makes programmers to program very simply without any difficulty." 
Python is the fastest-growing programming language in modern programming world''')  
Givenfileptr.close()
What will be the shown in the output when we run the above Python program?
  1. TypeError
  2. Python programming language is the modern day programming language. It makes programmers to program very simply without any difficulty.
  3. Python programming language is the modern day programming language. It makes programmers to program very simply without any difficulty.
  4. Python is the fastest-growing programming language in modern programming world
  5. Syntax Error
Answer: c. Python programming language is the modern day programming language. It makes programmers to program very simply without any difficulty. Python is the fastest-growing programming language in modern programming world Explanation: In the above program, we have opened the Givenfile with Python file handing syntax and use the w keyword which means we can write on the file. So, when in the next line the given statement is written in the file, it will be printed in the output while running the program. After that, the given file is closed. Hence, option C is the right answer.

38) Which one of the following given options is not one of the main classes of datetime classes in Python?

  1. date class
  2. time class
  3. deltatime class
  4. deltadate class
Answer: d. deltadate class Explanation: Following are the 6 classes in which datetime classes are mainly classified in Python programming language: date, time, datetime, deltatime, timezone and tzfinfo classes. Hence, option D is the right answer.

39) In Python file handling, what kind of access mode does 'rb' represent or works when used in the syntax?

  1. The 'rb' keyword used in the file opening syntax to open the given file in read-only mode.
  2. The 'rb' keyword used in the file opening syntax to open the given file in read-only in binary mode.
  3. The 'rb' keyword used in the file opening syntax to open the given file in read-only in append mode.
  4. The 'rb' keyword used in the file opening syntax to open the given file in both read and write mode.
Answer: b. The 'rb' keyword used in the file opening syntax to open the given file in read-only in binary mode. Explanation: When we use the 'rb' keyword with file name in Python file handling syntax, Python will open the file in read only in binary mode. We cannot modify after the file is opened. Hence, option B is the right answer.

40) In Python, the time class is treated as tuple of how many numbers when used in a program?

  1. 8 Numbers tuple
  2. 10 Numbers tuple
  3. 9 Numbers tuple
  4. 7 Numbers tuple
Answer: c. 9 Numbers tuple Explanation: In Python, when a time class is used in a program it is treated as a tuple of following 9 Numbers: Year, Month, Day, Hour, Minute, Second, Day of week, Day of year and Daylight savings. Hence, option C is the right answer.

41) Look at the following Python program:

import time 
for k in range(1,6): 
    print(k)
    time.sleep(3)
The above given program will print element from 1 to 5 in output when we run the program but all elements will not print simultaneously. After how much time of interval each element from 1 to 5 will be printed in Python output?
  1. 1 second
  2. 2 second
  3. 3 second
  4. 4 second
Answer: c. 3 second Explanation: In the above program, time function is imported. The for loop is defined for range between 1 to 6. So, elements from to 1 to 5 will be printed in the output. But since, time.sleep() function is given in the next line of code the elements will not print simultaneously. They will print after interval of 3 second each as given in the the argument of time.interval() function. Hence, option C is the right answer.

42) Which of the following given option is not a regrex function that are used in Python?

  1. search function
  2. merge function
  3. findall function
  4. match function
Answer: b. merge function Explanation: In Python, following are the regrex function that are used in a Python program:
  1. match function
  2. findall function
  3. sub function
  4. search function
  5. split function
Hence, option B is the right answer.

43) Look at the following Python program:

import re 
mkr = "How are you doin bro? How is everything going around you" 
matching = re.search("How", mkr) 
print(matching.group())
What will be printed in the output when we run the above code?
  1. How are you doin bro?
  2. How are you doin bro? How is everything going around you
  3. How is everything going around you
  4. How
Answer: d. How Explanation: In the above code, a string mkr is defined and then we used search function on it for 'How' word. So, when we printed group from matching it will print the word which is matched from the string that we have given in search argument. Hence, option D is the right answer.

44) Which protocol is used to handle the email transfer using Python programming language?

  1. Simple Mail Transfer Protocol (SMTP)
  2. Sorted Mail Transfer Protocol (SMTP)
  3. Pre Office Protocol (PCP)
  4. Internet Message Append Protocol (IMAP)
Answer: a. Simple Mail Transfer Protocol (SMTP) Explanation: Python uses Simple Mail Transfer Protocol (SMTP) to handle the email transfer process over the network. Hence, option A is the right answer.

45) Which of the following module is defined in Python that is used to defined a SMTP client session?

  1. numpy module
  2. dollar module
  3. smtplib module
  4. localhost module
Answer: c. smtplib module Explanation: A 'smtplib' module is provided to us in Python that is used to define SMTP protocol for client session objects which is used to send emails to various machines over the internet. Hence, option C is the right answer.

46) Which of the following option correctly describe that what 'csv.get_dialect' Python CSV module function returns in the output?

  1. This module function returns the current maximum field size allowed by the parser for the CSV file opened that is in Python.
  2. This module function returns the names of all dialects registered with the CSV file that is opened in Python.
  3. This module function associates dialect with a name from the CSV file that is opened in Python.
  4. This module function returns the dialect which is associated with the name for the CSV file that is opened in Python.
Answer: d. This module function returns the dialect which is associated with the name for the CSV file that is opened in Python. Explanation: The 'csv.get_dialect' CSV module function in Python is used when we open a CSV file with Python. The 'csv.get_dialect' module function returns the dialect which is associated with the name for the CSV file that is opened in Python. Hence, option D is the right answer.

47) Which of the following option correctly describe that what 'csv.register_dialect' Python CSV module function returns in the output?

  1. This module function returns the current maximum field size allowed by the parser for the CSV file opened that is in Python.
  2. This module function returns the names of all dialects registered with the CSV file that is opened in Python.
  3. This module function associates dialect with a name from the CSV file that is opened in Python.
  4. This module function returns the dialect which is associated with the name for the CSV file that is opened in Python.
Answer: c. This module function associates dialect with a name from the CSV file that is opened in Python. Explanation: The 'csv.register_dialect' CSV module function in Python is used when we open a CSV file with Python. The 'csv.register_dialect' module function associates dialect with a name from the CSV file that is opened in Python. The name with which the dialect is associated must be in the form of a string or in Unicode. Hence, option C is the right answer.

48) Which of the following module from the given options we need to import in our program to read, open and write excel file in Python?

  1. pip module
  2. Numpy module
  3. smtplib module
  4. xlrd module
Answer: d. xlrd module Explanation: To read, open and write excel file in Python, we need to import xlrd module in our program. We can import the xlrd module in our Python program using 'import xlrd' line of code in our program and then we will be able to read any excel file in Python. Hence, option D is the right answer.

49) Which of the following Python module from the given options is not used to read excel file in the Python program?

  1. xlrd module
  2. Excelrd module
  3. pandas as pd module
  4. openpyxl module
Answer: b. Excelrd module Explanation: We can import any one of given three i.e., xlrd, pandas as pd and openpyxl module in our Python program to read any excel file with the help of Python. Hence, option B is the right answer.

50) Which of the following option correctly describe that what 'csv.list_dialects' Python CSV module function returns in the output?

  1. This module function returns the current maximum field size allowed by the parser for the CSV file opened that is in Python.
  2. b. This module function returns the names of all dialects registered with the CSV file that is opened in Python.
  3. This module function associates dialect with a name from the CSV file that is opened in Python.
  4. This module function returns the dialect which is associated with the name for the CSV file that is opened in Python.
Answer: b. This module function returns the names of all dialects registered with the CSV file that is opened in Python. Explanation: The 'csv.list_dialects' CSV module function in Python is used when we open a CSV file with Python. The 'csv.list_dialects' module function returns the names of all dialects registered with the CSV file that is opened in Python. Hence, option B is the right answer.

51) Look at the following Python program:

class stop:
   def __init__(self):
         print "Hello New Python programmers at TutorialandExample"
   def __init__(self):
         print "Bye Python Developers! We will see you soon again"
obj = stop()
What will be printed in the output, when we run the above given code?
  1. Bye Python Developers! We will see you soon again
  2. Hello New Python programmers at TutorialandExample
  3. Hello New Python programmers at TutorialandExample
Bye Python Developers! We will see you soon again
  1. Syntax Error
Answer: a. Bye Python Developers! We will see you soon again Explanation: In the above given program, a class 'stop' is defined. In the class, first default function is initiated with a print statement i.e., Hello New Python programmers at TutorialandExample. But then default function is initiated with another print statement i.e., Bye Python Developers! We will see you soon again. So, when the object calls the stop class in the last line, the stop class will only print last print statement by which default function is initiated. Hence, option A is the right answer.

52) Look at the following Python program:

x = 'Cup'
y = 'Coffee'
z = y-x
print(z)
What will be printed in the output, when we run the above given code?
  1. Syntax Error
  2. Cup
  3. Coffee
  4. TypeError
Answer: d. TypeError Explanation: In the above program, two strings x and y are defined with elements in them. In the next line of code, we have defined 'z = y-x' and it will show an TypeError in the output. This is because both x and y are string variable and '-' is subtraction operator and the subtraction operator is an unsupported operand type for the string. So, when we run the above given program it will show a TypeError in output. Hence, option D is the right answer.

53) Look at the following Python program

alphabets = []  
for letter in 'TUTORIALANDEXAMPLE':  
    alphabets.append(letter)
print(alphabets)
What will be shown in the output when we run the above code in Python?
  1. [T U T O R I A L A N D E X A M P L E]
  2. [T, U, T, O, R, I, A, L, A, N, D, E, X, A, M, P, L, E]
  3. ['T', 'U', 'T', 'O', 'R', 'I', 'A', 'L', 'A', 'N', 'D', 'E', 'X', 'A', 'M', 'P', 'L', 'E']
  4. ['T' 'U' 'T' 'O' 'R' 'I' 'A' 'L' 'A' 'N' 'D' 'E' 'X' 'A' 'M' 'P' 'L' 'E']
Answer: c. ['T', 'U', 'T', 'O', 'R', 'I', 'A', 'L', 'A', 'N', 'D', 'E', 'X', 'A', 'M', 'P', 'L', 'E'] Explanation: In the above program, a list comprehension with 'alphabets' is defined. Then, the word 'TUTORIALANDEXAMPLE' is stored in the list comprehension 'alphabets' with the list comprehension method. In the next line of code, we printed 'alphabets' list comprehension and Python will print it in a form of list i.e., ['T', 'U', 'T', 'O', 'R', 'I', 'A', 'L', 'A', 'N', 'D', 'E', 'X', 'A', 'M', 'P', 'L', 'E']. Hence, option C is the right answer.

54) In which version of Python and year, Python collection module was released for all its users and developers?

  1. Python version 2.3 in 2005
  2. Python version 2.4 in 2003
  3. Python version 2.4 in 2004
  4. Python version 2.3 in 2003
Answer: c. Python version 2.4 in 2004 Explanation: Python released stable 2.4 version for it's all users and developers in the year 2004. In the Python 2.4 version, Python pushed a major update in which it introduced the Python collection module for all the users and Developers. Hence, option C is the right answer.

55) Look at the following Python program:

from collections import defaultdict      
alphabet = defaultdict(int)      
alphabet['x'] = 1      
alphabet['y'] = 2      
print(alphabet['z'])
What will be shown in the output when we run the above code in Python?
  1. 0
  2. 1
  3. 2
  4. TypeError
Answer: a. 0 Explanation: In the above given code, dictionary module is imported from Python. Then a dictionary name 'alphabet' is defined in next line which will only store integer data type values. Then we defined two dictionary collections i.e., x and y. But in next line, we give the argument to print z dictionary collection which is not defined in alphabet. So, according to default in defaultdict module, Python will print 0 in output for not defined dictionary collections. Hence, option A is the right answer.

56) What of the following given options correctly describe the function of deque() module in a Python program?

  1. It is a subclass of the Python dictionary object which helps user to count hashable objects present in the program.
  2. It is a double-ended queue which allows the user to add and remove elements from both ends of the dictionary defined in the program.
  3. It is a class that is used for grouping multiple dictionary present in a Python program together to create and print a single list in output.
  4. It is a subclass for the built-in dictionary class in the Python that provides all the method used on a dictionary defined in the program.
Answer: b. It is a double-ended queue which allows the user to add and remove elements from both ends of the dictionary defined in the program. Explanation: The deque() is double-ended queue module given by Python that is used by users for adding and removing elements from both ends of the dictionary defined in a program. Hence, option B is the right answer.

57) What of the following given options correctly describe the function of Counter() module in a Python program?

  1. It is a double-ended queue which allows the user to add and remove elements from both ends of the dictionary defined in the program.
  2. It is a class that is used for grouping multiple dictionary present in a Python program together to create and print a single list in output.
  3. It is a subclass for the built-in dictionary class in the Python that provides all the method used on a dictionary defined in the program.
  4. It is a subclass of the Python dictionary object which helps user to count hashable objects present in the program.
Answer: d. It is a subclass of the Python dictionary object which helps user to count hashable objects present in the program. Explanation: The Counter() module is subclass provided by Python for Python dictionary objects that help users to count all the hashable objects present in the given program. Hence, option D is the right answer.

58) Look at the following Python program:

import math 
GivenDigit = math.factorial(8.3) 
print("The factorial of the number using Python math factorial function defined in our program is:",GivenDigit)
What will be shown in the output when we run the above code in Python?
  1. The factorial of the number using Python math factorial function defined in our program is: 40,320
  2. ValueError in output
  3. The factorial of the number using Python math factorial function defined in our program is: 77,035.558
  4. The factorial of the number using Python math factorial function defined in our program is: 1
Answer: b. ValueError in output Explanation: In the above given code, Python math module is imported for using mathematical operations in the program. Then, a variable with GivenDigit name is defined and math.factorial() function is used on it. But the number given in the argument is 8.3 and according to the property of math.factorial() function, if the number given in the argument of the function is not integral then this function will show ValueError in the output. Hence, option B is the right answer.

59) Look at the following Python program:

import math 
GivenDigit = math.pow(11,3) 
print("The output of the number using Python math pow function defined in the program is:",GivenDigit)
What will be shown in the output when we run the above code in Python?
  1. The output of the number using Python math pow function defined in the program is: 11
  2. The output of the number using Python math pow function defined in the program is: 3
  3. The output of the number using Python math pow function defined in the program is: 33
  4. The output of the number using Python math pow function defined in the program is: 1331
Answer: d. The output of the number using Python math pow function defined in the program is: 1331 Explanation: In the above given code, Python math module is imported for using mathematical operations in the program. Then, a variable with GivenDigit name is defined and math.pow() function is used on it. This function is used to calculate the power of the number. The first argument in this function is taken as digit and the second argument is taken in the function is taken as power of digit i.e., math.pow(x,y) = xy. Hence, option D is the right answer.

60) Which of the following conditions correctly describes where a function is called in the Python program?

  1. When the Python function is defined inside of the given class in program
  2. When the Python function is defined outside of the given class in program
  3. When the Python function is defined both outside and inside of the class in program
  4. None of the above
Answer: a. When the Python function is defined inside of the given class in program Explanation: In any given Python program, a method is called whenever a Python function is defined inside of the class in the program. Hence, option A is the right answer.