Python Dictionary MCQ : Set 1
Python Dictionary MCQ 1). What is a dictionary in Python? a) An ordered collection of elements b) A sequence of key-value pairs c) A data structure for storing integers d) A built-in function in Python Corresct answer is: b) A sequence of key-value pairs Explanation: A dictionary in Python is
Python Tuple MCQ : Set 4
Python Tuple MCQ 1). What is the output of the following code? l = [(” “,), (‘a’, ‘b’), (‘a’, ‘b’, ‘c’), (‘d’,), ()] print(“Original list of tuples: “, l) for tup in l: if len(tup) == 0: l.remove(tup) print(“After removing empty tuples: “, l)
Python Tuple MCQ : Set 3
Python Tuple MCQ 1). What is the output of the following code? tup = (‘s’, ‘q’, ‘a’, ‘t’, ‘o’, ‘o’, ‘l’, ‘s’) str1 = ” for char in tup: str1 += char print(“String: “, str1) a). String: ‘s’, ‘q’, ‘a’, ‘t’, ‘o’, ‘o’, ‘l’, ‘s’ b). String: ‘sqltools’
Python Tuple MCQ : Set 2
Python Tuple MCQ 1). Which of the following methods is used to insert an element at a specific index in a tuple? a) insert() b) add() c) append() d) extend() Correct answer is: a Explanation: There is no built-in method to insert an element at a specific index in a
Python Tuple MCQ : Set 1
Python Tuple MCQ 1). What is a tuple in Python? a) A mutable data type b) An immutable data type c) A collection of key-value pairs d) A dynamic array Correct answer is: b Explanation: A tuple is an immutable data type in Python, meaning its elements cannot be modified
Python String MCQ : Set 4
Python String MCQ 1). What does the following code do? string1 = “I want to eat fast food” print(“Occurrences of food: “, string1.count(“food”)) a) It prints the number of occurrences of the word “food” in the string. b) It counts the number of words in the string. c) It checks
Python String MCQ : Set 3
Python String MCQ 1). What is the value of result after executing the given code? str1 = “Sqa Tools Learning”result = “”vowels = [“a”,”e”,”i”,”o”,”u”,“A”,”E”,”I”,”O”,”U”] for char in str1: if char in vowels: result = result + char*3 else: result = result +
Python String MCQ : Set 2
Python String MCQ 1). Which method is used to check if a string contains only printable characters? a) isprintable() b) isdisplayable() c) isvisible() d) isprintchar() Correct answer is: a) isprintable() Explanation: The isprintable() method checks if a string contains only printable characters. 2). What is the output of the following
Python String MCQ : Set 1
Python String MCQ 1). Which of the following methods is used to find the length of a string in Python? a) length() b) len() c) size() d) count() Correct answer is: b) len() Explanation: The len() function returns the length of a string in Python. 2). What does the “+”
Python List MCQ : Set 4
Python List MCQ 1). Which method can be used as an alternative to the min() function to find the minimum value from a list? a) sort() b) reverse() c) pop() d) append() Correct answer is: a) sort() Explanation: The sort() method can be used to sort the list in ascending
Python List MCQ : Set 3
Python List MCQ 1). What is the output of the following code? a = [22, 66, 89, 9, 44]print(“Minimum: “, min(a)) a) Minimum: 9b) Minimum: 22c) Minimum: 44d) Minimum: 89 Correct answer is: a) Minimum: 9Explanation: The min() function returns the minimum value from the list ‘a’, which is 9 in this case. 2).
Python List MCQ : Set 2
Python List MCQ 1). Which method is used to check if any element in a list satisfies a certain condition? a) any() b) some() c) exists() d) satisfy_any() Correct answer is: a) any() Explanation: The any() method is used to check if any element in a list satisfies a certain
Python List MCQ : Set 1
Python List MCQ 1). What is a list in Python? a) A collection of unordered elements b) A collection of ordered elements c) A collection of unique elements d) A collection of numeric elements Correct answer is: b) A collection of ordered elements Explanation: A list in Python is an
Python Conditional Statements MCQ: Set 4
Python Conditional Statements MCQ 1). What is the output of the following code? num1 = 12.6 if type(num1) == float: print(“True”) else: print(“False”) a) Trueb) Falsec) Errord) None Correct answer is:a) TrueExplanation: The code checks if the type of `num1` is equal to `float`. Since `num1` is assigned the value
Python Conditional Statements MCQ: Set 3
Python Conditional Statements MCQ 1). What is the output of the following code? age = 20 if age >= 18: print(“You are eligible”) else: print(“You are not eligible”) a) You are eligibleb) You are not eligiblec) No outputd) Error Correct answer is:a) You are eligibleExplanation: The condition `age >= 18`
Python Conditional Statements MCQ: Set 2
Python conditional statements MCQ 1). What is the output of the following code? x = 10 if x < 5: print("A") elif x > 15: print(“B”) else: print(“C”) a) Ab) Bc) Cd) No output Correct answer is:c) CExplanation: The condition x < 5 is False. The condition x > 15
Python conditional statements MCQ: Set 1
Python conditional statements MCQ 1). What is the purpose of an if statement in Python? a) To check if a condition is True or Falseb) To perform a loopc) To define a functiond) To import a module Correct answer is: a) To check if a condition is True or FalseExplanation:
Python Loop MCQ : Set 4
Python Loop MCQ 1). What is the output of the following code? for i in range(5): if i % 2 == 0: continue print(i) a) 1 3 b) 0 2 4 c) 1 2 3 4 d) 0 1 2 3 4
Python Loop MCQ : Set 3
Python Loop MCQ 1). What is the output of the following code? for i in range(5): if i == 2: break print(i)else: print(“Loop completed”) a) 0 1b) 0 1 2c) 0 1 2 3 4d) Loop completed Correct answer is: a) 0 1Explanation: The
Python Loop MCQ : Set 2
Python Loop MCQ 1). Which loop control statement is used to terminate the loop prematurely and transfer control to the next iteration?a) continueb) exitc) breakd) pass Correct answer is: c) breakExplanation: The break statement is used to terminate a loop prematurely and transfer control to the next statement after the
Python Loop MCQ : Set 1
Python Loop MCQ 1). What is a loop in Python?a) A data structureb) A control flow statementc) A mathematical operationd) A file handling technique Correct answer is: b) A control flow statementExplanation: A loop is a control flow statement that allows executing a block of code repeatedly until a certain
Python Variable MCQ : Set 4
Python Variable MCQ 1). What is the output of the following code? x = [1, 2, 3] y = x.copy() y[0] = 10 print(x) a) [1, 2, 3] b) [10, 2, 3] c) [1, 2, 3, 10] d) None of these Correct answer is a) Explanation: The copy() method creates
Python Variable MCQ : Set 3
Python Variable MCQ 1). What will be the value of the following variable?a = 10a += 5a -= 3 a) 5b) 7.5c) 10d) 12 Correct answer is d)Explanation: The code performs arithmetic operations on the variable “a”. The final value of “a” will be 12. 2). What is the scope
Python Variable MCQ : Set 2
Python Variable MCQ 1). What will be the output of the following Python code?type(10.0) a) <class ‘float’> b) <class ‘int’> c) <class ‘list’> d) None of these Correct answer is a).Explanation: The value 10.0 is float, so the output of the given code will be <class ‘float’>. 2). What will be the
Python variable MCQ : Set 1
Python Variable MCQ 1). Which is the correct way to get the type of the variable, say for variable x that holds any kind of value? a) typedef (x) b) pytype (x) c) type (x) d) None of these Correct answer is c). Explanation: Type is a built-in
48. Problem to create an inheritance example in Python
In this Python oops program, we will create an inheritance example in Python. Python class called Dog that inherits from the Animal class. Inheritance example in Python Steps to solve the program The Dog class extends the Animal class, which means it inherits the properties and methods of the Animal
47. Problem to create an inheritance example in Python
In this Python oops program, we will create an inheritance example in Python. Python class called Animal with attributes name and color. Inheritance example in Python Steps to solve the program The Animal class has a constructor method __init__ that takes two parameters: name and color. It initializes two instance
46. Problem to create a Python class example
In this Python oops program, we will create a Python class example. Python class called ShoppingCart with attributes items and total_cost. Python class example Steps to solve the program The ShoppingCart class has a constructor method __init__ that initializes two instance variables: self.items as an empty list to store the
45. Problem to create an inheritance example in Python
In this Python oops program, we will create an inheritance example in Python, Python class called EBook that inherits from the Book class. Inheritance example in Python Steps to solve the program The Book class is defined with a constructor method __init__ that takes title, author, and pages as parameters
44. Problem to create a Python class example
In this Python oops program, we will create a Python class example. Python class called Book with attributes title, author, and pages. Python class example Steps to solve the program The Book class is defined with a constructor method __init__ that takes title, author, and pages as parameters and initializes