NumPy MCQ : Set 4
NumPy MCQ 1). What is the output of the following code? import numpy as np x = np.array([6, 8, 3, 5]) print(np.all(x)) a) True b) False c) 0 d) [True, True, True, True] Correct answer is: b) False Explanation: The code snippet imports the NumPy library and creates an array
NumPy MCQ : Set 3
NumPy MCQ 1). What is the purpose of the np.random.rand() function? a) Generates a random integer b) Returns a random permutation of an array c) Generates an array of random floats in the range [0, 1) d) Calculates the cumulative sum of an array Correct answer is: c) Generates an
NumPy MCQ : Set 2
NumPy MCQ 1). What does the `np.unique()` function do? a) Removes duplicate elements from an array b) Returns the element-wise square of an array c) Computes the cumulative sum of an array d) Performs element-wise division of two arrays Correct answer is: a) Removes duplicate elements from an array Explanation:
NumPy MCQ : Set 1
NumPy MCQ 1). What is NumPy? a) A programming language b) A numerical computing library for Python c) A data visualization library d) A machine learning framework Correct answer is: b) A numerical computing library for Python Explanation: NumPy is a powerful library for numerical computing in Python. It offers
Python Pandas MCQ : Set 6
Python Pandas MCQ 1). What is the output of the following code? import pandas as pd import numpy as np d = {‘Sr.no.’: [1, 2, 3, 4], ‘Name’: [‘Alex’, ‘John’, ‘Peter’, ‘Klaus’], ‘Age’: [30, np.nan, 29, np.nan]} df = pd.DataFrame(d) print(“Nan values in the dataframe: “, df.isnull().values.sum()) a) 0 b)
Python Pandas MCQ : Set 5
Python Pandas MCQ 1). What is the output of the following code? import pandas as pd df = pd.Series([‘2 Feb 2020′,’5/11/2021′,’7-8-2022’]) print(“Converting series of date strings to a timeseries:”) print(pd.to_datetime(df)) a) 0 2020-02-02 1 2021-05-11 dtype: datetime64[ns] b) 0 Feb 02, 2020 1 May 11, 2021 2 Jul 08, 2022
Python Pandas MCQ : Set 4
Python Pandas MCQ 1). What is the output of the following code? import pandas as pd df = pd.Series([15, 43, 88, 23]) print(df) a) 15, 43, 88, 23 b) [15, 43, 88, 23] c) 0 15 1 43 2 88 3 23 dtype: int64 d) None of the above Correct
Python Pandas MCQ : Set 3
Python Pandas MCQ 1). What is the purpose of the `value_counts()` function in Pandas? a) To calculate the cumulative sum of a column b) To count the occurrences of each unique value in a column c) To sort a DataFrame based on a specific column d) To remove duplicate rows
Python Pandas MCQ : Set 2
Python Pandas MCQ 1). What is the purpose of the `iloc` attribute in Pandas? a) To access rows and columns of a DataFrame by their index location b) To access rows and columns of a DataFrame by their label c) To access rows and columns of a DataFrame by their
Python Pandas MCQ : Set 1
Python Pandas MCQ 1). What is Pandas? a) A Python package for data analysis and manipulationb) A Python framework for web developmentc) A Python module for machine learningd) A Python library for graphical plotting Correct answer is: a) A Python package for data analysis and manipulationExplanation: Pandas is a popular
Python OOPS MCQ : Set 4
Python OOPS MCQ 1). What is the output of the following code? class Rectangle: def __init__(self, length, width): self.length = length self.width = width def calculate_area(self): return self.length * self.width def calculate_perimeter(self): return 2 * (self.length + self.width) # Create an object of the Rectangle class rectangle = Rectangle(5, 13)
Python OOPS MCQ : Set 3
Python OOPS MCQ 1). What is the output of the following code? class MyClass: def __init__(self, name): self.name = name def display_name(self): print(“Name:”, self.name) # Create an object of the class obj = MyClass(“Omkar”) obj.display_name() Correct answer is: a) Name: Omkar Explanation: The code defines a class called `MyClass` with
Python OOPS MCQ : Set 2
Python OOPS MCQ 1). What is the purpose of the `@classmethod` decorator in Python? a) It allows a method to be called without creating an instance of the class. b) It converts a class method into an instance method. c) It enables inheritance between classes. d) It defines a method
Python OOPS MCQ : Set 1
Python OOPS MCQ 1). Which of the following assertions most accurately sums up Python’s encapsulation? a) It is a process of hiding the implementation details of a class. b) It is a process of creating multiple instances of a class. c) It is a process of defining attributes and methods
Python Features and Its Contribution
Python, a popular high-level programming language,has gained immense popularity over the years due to its simplicity, versatility, and extensive range of features. It has emerged as a go-to language for developers, data scientists, and AI enthusiasts. In this article, we will explore the various features of Python and its significant
Python File Handling MCQ : Set 4
Python File Handling MCQ 1). What is the purpose of the following code? file = open(‘file.txt’) data = file.read().split() m_num = [] for val in data: if val.isnumeric(): if len(val) == 10: m_num.append(val) print(“Mobile numbers in the file: “, m_num) a) Read the contents of the file and split them
Python File Handling MCQ : Set 3
Python FIle Handling MCQ 1). What is the output of the following code? f = open(“file1”, “a”) f.write(“nlearning python is fun”) f.close() a) The code appends the string “learning python is fun” to the file named “file1” and then closes the file.b) The code opens the file named “file1” for
Python File Handling MCQ : Set 2
Python File Handling MCQ 1). Which method is used to truncate a file to a specified size in Python? a) truncate() b) resize() c) reduce() d) shrink() Correct answer is: a) truncate() Explanation: The `truncate()` method is used to truncate a file to a specified size in Python. If the
Python File Handling MCQ : Set 1
Python File Handling MCQ 1). What is file handling in Python? a) A mechanism to handle errors in file operationsb) A way to create new files in Pythonc) A process of working with files, such as reading from or writing to themd) A method to encrypt files in Python Correct
Python Function MCQ : Set 4
Python Function MCQ 1). What is the output of the following code? def square(d): a = {} for key,value in d.items(): a[key] = value**2 return a square({‘a’:4,’b’:3,’c’:12,’d’:6}) a) {‘a’: 16, ‘b’: 9, ‘c’: 144, ‘d’: 36} b) {‘a’: 8, ‘b’:
Python Function MCQ : Set 3
Python Function MCQ 1). What is the purpose of the given Python function? def add(a,b): total = a+b print(“Total: “,total) num1 = int(input(“Enter number 1: “)) num2 = int(input(“Enter number 2: “)) add(num1,num2) a) It multiplies two numbers and prints the result. b) It divides two
Python Function MCQ : Set 2
Python Function MCQ 1). What is the purpose of the “return” statement in Python? a) It defines a loop.b) It handles exceptions.c) It terminates the execution of a loop.d) It specifies the value to be returned by a function. Correct answer is: d) It specifies the value to be returned
Python Function MCQ : Set 1
Python Function MCQ 1). Which keyword is used to define a function in Python? a) def b) func c) define d) function Correct answer is: a) def Explanation: The keyword “def” is used to define a function in Python. 2). In a function what is the purpose of a return
Python Set MCQ : Set 4
Python Set MCQ 1). What is the output of the following code? a = {1, 2, 4, 5, 7, 8, 9} print(“Original set1: “, a) print(type(a)) a) Original set1: {1, 2, 4, 5, 7, 8, 9} <class ‘set’> b) Original set1: {1, 2, 4, 5, 7, 8, 9} <class ‘list’>
Python Set MCQ : Set 3
Python Set MCQ 1). What is the output of the following code? List = [1, 2, 3, 4, 5] list_set = set(List) print(“Original list: “, List) print(“List to set: “, list_set) a) Original list: [1, 2, 3, 4, 5] List to set: {1, 2, 3, 4, 5} b) Original list:
Python Set MCQ : Set 2
Python Set MCQ 1). Which method is used to return the minimum element from a set? a) min() b) minimum() c) smallest() d) get_min() Correct answer is: a) min() Explanation: The min() function is used to return the minimum element from a set. 2). Which method is used to calculate
Python Set MCQ : Set 1
Python Set MCQ 1). What is a set in Python? a) A sequence of elementsb) A collection of unordered and unique elementsc) A data structure used for sorting elementsd) A variable that can store multiple values Correct answer is: b) A collection of unordered and unique elementsExplanation: In Python, a
Python Dictionary MCQ : Set 4
Python Dictionary MCQ 1). What is the output of the following code? dict1 = {“m1”: 40, “m2”: 50, “m3”: None} dict2 = {} for key, val in dict1.items(): if val != None: dict2[key] = val print(dict2) a) {“m1”: 40, “m2”: 50} b) {“m1”: 40,
Python Dictionary MCQ : Set 3
Python Dictionary MCQ 1). What is the output of the following code? dict1 = {‘course’:’python’,’institute’:’sqatools’ } dict2 = {‘name’:’omkar’} dict2.update(dict1) print(dict2) a) {‘name’: ‘omkar’} b) {‘name’: ‘omkar’, ‘course’: ‘python’, ‘institute’: ‘sqatools’} c) {‘course’: ‘python’, ‘institute’: ‘sqatools’} d) {‘course’: ‘python’, ‘institute’: ‘sqatools’, ‘name’: ‘omkar’} Corresct answer is: d) {‘course’: ‘python’, ‘institute’:
Python Dictionary MCQ : Set 2
Python Dictionary MCQ 1). Which method returns a string representation of a dictionary? a) str() b) repr() c) string() d) __str__() Corresct answer is: d) __str__() Explanation: The __str__() method returns a string representation of a dictionary. It can be customized by overriding the method in a custom dictionary class.