1.
Which of the following is correct about Python?
Correct Answer
D. All of the above
Explanation
Python is a versatile programming language that possesses several characteristics. It is a high-level language, meaning it provides abstractions that make it easier to write and understand code. It is also interpreted, allowing for immediate execution of code without the need for compilation. Python is interactive, allowing users to experiment and test code in real-time. Additionally, it is object-oriented, which means it organizes data and functions into objects for more efficient programming. Python is designed to prioritize readability, using English keywords instead of punctuation and having fewer syntactical constructions compared to other languages. Therefore, all of the given statements are correct about Python.
2.
Which of the following function convert a String to an object in python?
Correct Answer
B. Eval(str)
Explanation
The eval() function in Python can be used to convert a string into an object. It takes a string as input and evaluates it as a Python expression, returning the resulting object. This can be useful when working with dynamically generated code or when needing to convert a string representation of an object back into its original form. The repr() function returns a string representation of an object, while the tuple() and list() functions convert a sequence into a tuple and list respectively.
3.
Which of the following operator in python evaluates to true if it does not finds a variable in the specified sequence and false otherwise?
Correct Answer
D. Not in
Explanation
The "not in" operator in Python evaluates to true if it does not find a variable in the specified sequence and false otherwise. It is used to check if a value does not exist in a given sequence, such as a list or a string. If the value is not found in the sequence, the operator returns true. Otherwise, it returns false.
4.
What is the following function returns the lowest index in list that obj appears?
Correct Answer
A. List.index(obj)
Explanation
The correct answer is "list.index(obj)". This function returns the lowest index in the list where the specified object "obj" appears. It searches for the first occurrence of the object and returns its index. If the object is not found in the list, it raises a ValueError.
5.
What does the following code do?→def a(b, c, d): pass
Correct Answer
B. Defines a function, which does nothing
Explanation
The given code defines a function named "a" with three parameters: b, c, and d. However, the function body is empty as it only contains the "pass" statement. This means that the function does nothing and serves as a placeholder or a stub that can be filled with actual code later on.
6.
Which of these in not a core datatype?
Correct Answer
D. Class
Explanation
The question asks for a core datatype, and the options provided are Lists, Dictionary, Tuples, and Class. Lists, Dictionary, and Tuples are all core datatypes in Python, but Class is not considered a core datatype. In Python, a class is a blueprint for creating objects, and it is used for creating user-defined objects with their own methods and attributes. Therefore, the correct answer is Class.
7.
What is the return value of trunc() ?
Correct Answer
A. Int
Explanation
The return value of the trunc() function is an integer. This function is used to remove the decimal part of a number and return the integer value. Therefore, the correct answer is int.
8.
Given a function that does not return any value, what value is shown when executed at the shell?
Correct Answer
D. None
Explanation
When a function does not return any value, it means that it has a return type of void. In programming, void is used to indicate that a function does not return any value. Therefore, when this function is executed at the shell, the value shown would be None.
9.
Which of these is not a core data type?
Correct Answer
D. Class
Explanation
The correct answer is Class. In Python, lists, dictionaries, and tuples are all considered core data types because they are built-in and commonly used to store and manipulate data. However, a class is not a core data type but rather a blueprint for creating objects. Classes are used to define the structure and behavior of objects, allowing for code reusability and organization.
10.
Which of the following is correct about Python?
Correct Answer
B. It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java
Explanation
Python can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java. This means that Python can interact and communicate with code written in these languages and technologies. This allows for seamless integration and collaboration between different programming languages and platforms, making Python a versatile and flexible language for various applications.
11.
Which of the following is correct about tuples in python?
Correct Answer
B. A tuple consists of a number of values separated by commas.
Explanation
Tuples in Python are similar to lists as they are both sequence data types. However, tuples are enclosed within parentheses and consist of a number of values separated by commas. Therefore, the correct statement about tuples in Python is that "A tuple consists of a number of values separated by commas."
12.
Which of the following functions is a built-in function in python?
Correct Answer
D. Print()
Explanation
The function "print()" is a built-in function in Python. It is used to display output on the console or terminal. The print() function takes one or more arguments and prints them as text. It is commonly used for debugging purposes and to display information to the user during program execution.
13.
How many keyword arguments can be passed to a function in a single function call?
Correct Answer
C. Zero or more
Explanation
In Python, keyword arguments can be passed to a function in a single function call. The number of keyword arguments can be zero or more, meaning that it is not mandatory to pass any keyword arguments, but if needed, multiple keyword arguments can be provided. This allows for flexibility and customization when calling a function, as specific arguments can be passed by their names, rather than relying solely on their position in the function call.
14.
Given a function that does not return any value, What value is thrown by default when executed in shell
Correct Answer
D. None
Explanation
When a function does not return any value, it is said to have a return type of "void". In programming languages like C or C++, when a function with a void return type is executed, it does not throw any value or result. Therefore, the default value thrown by such a function when executed in a shell is "None".
15.
In order to store values in terms of key and value we use what core datatype
Correct Answer
D. Dictionary
Explanation
To store values in terms of key and value, we use the core datatype called a dictionary. A dictionary is a collection of key-value pairs, where each key is unique and associated with a value. It allows efficient retrieval of values based on their corresponding keys. Unlike lists or tuples, which store values in a sequential manner, a dictionary provides a way to organize and access data based on meaningful keys. Therefore, a dictionary is the appropriate core datatype for storing values in key-value pairs.
16.
What is max(3, 5, 1, 7, 4)?
Correct Answer
D. 7
Explanation
The correct answer is 7 because the max() function is used to find the highest value among the given numbers. In this case, the highest value among 3, 5, 1, 7, and 4 is 7.
17.
What is round(3.52)?
Correct Answer
D. 4
Explanation
The round() function is used to round a given number to the nearest whole number. In this case, 3.52 is closer to 4 than to 3, so the correct answer is 4.
18.
In Python, a string literal is enclosed in __________.
Correct Answer
C. Single-quotes
Explanation
In Python, a string literal is enclosed in single-quotes. This means that when declaring a string, it should be surrounded by single quotation marks (' '). For example, 'Hello World' is a string literal in Python. Using single-quotes is one of the ways to define a string and is commonly used in Python programming.
19.
Suppose s is "\t\tWelcome\n", what is s.strip()?
Correct Answer
D. Welcome
Explanation
The strip() method in Python removes any leading or trailing whitespace characters from a string. In this case, the string s is "\t\tWelcome", which has leading and trailing tabs and newlines. When we apply the strip() method to s, it removes these leading and trailing whitespace characters, resulting in the string "Welcome". Therefore, the correct answer is "welcome".
20.
The following code displays ___________.
temperature = 50
if temperature >= 100:
print("too hot")
elif temperature
Correct Answer
C. just right
Explanation
The code will display "just right" because the temperature variable is set to 50, which is not greater than or equal to 100. Therefore, the if condition is not met and the code moves to the elif condition. Since there are no conditions specified for the elif statement, it will always be true and execute the following print statement, which is "just right".
21.
How many times will the following code print "Welcome to Python"?
count = 0
while count < 10:
print("Welcome to Python")
count += 1
Correct Answer
C. 10
Explanation
The given code will print "Welcome to Python" 10 times because the while loop will continue executing as long as the condition count < 10 is true. The count variable is initially set to 0, and each time the loop iterates, the count is incremented by 1. Therefore, the loop will run 10 times (count = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and print "Welcome to Python" each time.
22.
The function range(5) return a sequence ______________.
Correct Answer
D. 0, 1, 2, 3, 4
Explanation
The function range(5) returns a sequence starting from 0 up to, but not including, 5. So the correct answer is 0, 1, 2, 3, 4.
23.
What is "Programming is fun"[4: 6]?
Correct Answer
B. Ra
Explanation
The expression "Programming is fun"[4:6] is using slicing in Python to extract a substring from the original string. In Python, indexing starts from 0, so the index 4 corresponds to the letter 'a' in the original string, and the index 6 is not included in the slice. Therefore, the substring extracted is "ra".
24.
Given a string s = "Welcome", what is s.count('e')?
Correct Answer
B. 2
Explanation
The count() function in Python is used to count the number of occurrences of a substring within a string. In this case, the string s is "Welcome" and we are counting the occurrences of the letter 'e'. Since 'e' appears twice in the string, the correct answer is 2.
25.
Given a string s = "Programming is fun", what is s.find('m') ?
Correct Answer
C. 6
Explanation
The function s.find('m') returns the index of the first occurrence of the letter 'm' in the string s. In this case, the letter 'm' is located at index 6, so the correct answer is 6.
26.
What is "Good".replace("o", "e")?
Correct Answer
C. Geed
Explanation
When we replace the letter "o" with "e" in the word "Good", we get the word "Geed". This is because the letter "o" is substituted with the letter "e" in the word, resulting in the new word "Geed".
27.
To return the length of string s, use _________.
Correct Answer
B. Len(s)
Explanation
The len(s) function is used to return the length of a string in Python. It takes the string as an argument and returns the number of characters in the string. Therefore, len(s) is the correct way to return the length of the string s.
28.
How do you create a window?
Correct Answer
D. window = Tk()
Explanation
The correct answer is "window = Tk()". This line of code creates a window using the Tkinter library in Python. Tkinter is a standard Python interface to the Tk GUI toolkit, and "Tk()" is a function that creates a new window object. By assigning this function call to the variable "window", we can then manipulate and customize the window as needed.
29.
How do you create a frame?
Correct Answer
C. Frame = Frame()
Explanation
The correct answer is "frame = Frame()". This is because "Frame()" is a method in Python's tkinter module that creates a new window or frame. By assigning "frame" to "Frame()", we are creating a new frame object that can be used to build a graphical user interface. The other options, "newWindow()", "Window()", and "Tk()", do not exist as methods in the tkinter module and therefore would not create a frame.
30.
How do you create a GUI component for displaying multiple-lines of text?
Correct Answer
D. Use Message
Explanation
To create a GUI component for displaying multiple lines of text, the appropriate option is to use the "Use Message" function. The Message function allows the user to display text that spans across multiple lines, making it suitable for displaying longer messages or paragraphs. This function is specifically designed to handle multi-line text and provides a convenient way to present information in a visually appealing format within a graphical user interface.
31.
_______ are geometry managers in Tkinter.
Correct Answer
A. Pack
Explanation
In Tkinter, "pack" is one of the geometry managers. It is used to organize and arrange widgets in a block format, where each widget is placed below the previous one. The pack() method automatically adjusts the size of the widgets based on their content and fills the available space. It is a simple and easy-to-use geometry manager, making it suitable for basic GUI layouts.
32.
To place a button in a specified row and column in its parent container, use ________.
Correct Answer
B. Grid manager
Explanation
To place a button in a specified row and column in its parent container, the appropriate manager to use is the grid manager. The grid manager allows for precise placement of widgets in a grid-like structure, where each widget can be positioned in a specific row and column. This ensures that the button will be placed exactly where desired within its parent container.
33.
To create a menu in a window, use __________
Correct Answer
A. Menubar = Menu(window)
Explanation
To create a menu in a window, the correct way is to use "menubar = Menu(window)". This code creates a new menu bar object called "menubar" and associates it with the specified window. By passing the "window" parameter, it ensures that the menu bar is created within that specific window.
34.
_____________ displays a file dialog for saving a file.
Correct Answer
B. Filename = asksaveasfilename()
Explanation
The correct answer is "filename = asksaveasfilename()". This function is used to display a file dialog for saving a file. It allows the user to select a location and specify a file name for saving the file. The selected file name is then assigned to the variable "filename".
35.
Invoking the ___________ method converts raw byte data to a string.
Correct Answer
B. Decode()
Explanation
The decode() method is used to convert raw byte data to a string. This method is commonly used when working with encoded data, such as when decoding data received from a network or reading data from a file. By invoking the decode() method, the raw byte data is transformed into a readable string format that can be easily manipulated and understood by the programmer.
36.
Which function do you use to read data using binary input?
Correct Answer
C. load
Explanation
The function "load" is used to read data using binary input. This function is commonly used to retrieve data from a binary file or to load binary data into a program. It allows the program to read the binary representation of the data and convert it into a usable format within the program.
37.
Suppose s = {1, 2, 4, 3}, _______ returns 4.
Correct Answer
B. Len(s)
Explanation
The len(s) function returns the length of the given list or set. In this case, the set s has 4 elements, so len(s) will return 4.
38.
Suppose s1 = {1, 2, 4, 3} and s2 = {1, 5, 4, 13}, what is s1 & s2?
Correct Answer
C. {1, 4}
Explanation
The correct answer is {1, 4}. This is because the "&" operator between two sets returns the intersection of the two sets, which is the set of elements that are common to both sets. In this case, the only elements that are present in both s1 and s2 are 1 and 4, so the intersection of s1 and s2 is {1, 4}.
39.
Suppose d = {"john":40, "peter":45}, the keys are __________
Correct Answer
B. John and "peter"
Explanation
The correct answer is "john and 'peter'". This is because in the given dictionary d = {"john":40, "peter":45}, "john" and "peter" are the keys of the dictionary. The keys in a dictionary are the unique identifiers for the values associated with them. In this case, the values associated with the keys "john" and "peter" are 40 and 45 respectively.
40.
________ is a data structure to store data in a sequential order.
Correct Answer
A. A list
Explanation
A list is a data structure that allows storing data in a sequential order. It is a collection of elements where each element has a specific position or index. The elements in a list can be accessed and manipulated individually by their index values. Unlike sets and dictionaries, which do not have a specific order, a list maintains the order in which the elements are added. A heap, on the other hand, is a specialized tree-based data structure used to efficiently retrieve the maximum or minimum element. Therefore, a list is the correct answer for storing data in a sequential order.
41.
What is the number of edges in a complete graph of n vertices?
Correct Answer
C. N(n-1)/2
Explanation
A complete graph is a graph where each vertex is connected to every other vertex. In such a graph, the number of edges can be calculated using the formula n(n-1)/2, where n is the number of vertices. This formula is derived from the fact that each vertex is connected to n-1 other vertices, but we divide by 2 to avoid counting each edge twice. Therefore, the correct answer is n(n-1)/2.
42.
Suppose a list is [2, 9, 5, 4, 8, 1]. After the first pass of bubble sort, the list becomes
Correct Answer
D. 2, 5, 4, 8, 1, 9