Correct Answer: A) Use the + operator for lists
Explanation: The +
operator combines two lists by creating a new list containing all elements from both lists.
A) List is mutable and flexible
B) String is immutable in Python
C) Set is mutable in operations
D) Dictionary is changeable type
Correct Answer: B) String is immutable in Python
Explanation: Strings in Python cannot be modified after creation. Any operation on a string creates a new string instead of altering the original.
A) Use the + operator for lists
B) Use the append method in loops
C) Use the range function directly
D) Use the iter function on lists
Correct Answer: A) Use the + operator for lists
Explanation: The +
operator combines two lists by creating a new list containing all elements from both lists.
A) + for addition operation
B) // for integer division
C) and for logical comparison
D) % for modulus operation
Correct Answer: C) and for logical comparison
Explanation: The and
keyword is a logical operator used for conditional statements, not for arithmetic operations.
A) True because it’s valid
B) False because it’s empty
C) Error due to syntax
D) Null for invalid input
Correct Answer: B) False because it’s empty
Explanation: An empty list is considered False
in a boolean context in Python. Non-empty lists return True
.
A) Null for all static types
B) False for boolean values
C) Zero for all data types
D) Garbage for uninitialized
Correct Answer: B) False for boolean values
Explanation: In Java, static boolean variables are initialized to false
by default, while numeric types default to 0
.
A) Use the pop() function
B) Use the insert() function
C) Use the len() function
D) Use the append() function
Correct Answer: D) Use the append() function
Explanation: The append()
method adds an element to the end of the list without modifying existing elements.
A) pop() removes specific index
B) append() adds elements
C) clear() empties the list
D) count() finds occurrences
Correct Answer: A) pop() removes specific index
Explanation: The pop()
method removes and returns the element at a specific index, with the default being the last element.
A) <class ‘int’> for numerical
B) <class ‘NoneType’> output
C) <class ‘str’> for strings
D) <class ‘object’> general
Correct Answer: B) <class ‘NoneType’> output
Explanation: The type()
function returns <class 'NoneType'>
when passed None
, which is a unique data type in Python.
A) Use while(true) syntax
B) Use do-while(true) loop
C) Use for(;;) with no conditions
D) Use loop(true) for execution
Correct Answer: C) Use for(;;) with no conditions
Explanation: The for(;;)
syntax in Java creates an infinite loop by omitting all loop control parameters.
A) Tuples are immutable data types
B) Lists can only hold strings
C) Tuples use square brackets
D) Lists cannot hold duplicates
Correct Answer: A) Tuples are immutable data types
Explanation: Tuples cannot be modified after creation, while lists are mutable and allow changes.
A) lambda function() inner()
B) function(outer): call inner
C) def outer(): def inner()
D) init function(): nested defs
Correct Answer: C) def outer(): def inner()
Explanation: In Python, nested functions are written by defining one function inside another, enabling encapsulated logic.
A) 10 as an integer result
B) 55 as a concatenated string
C) Error in type coercion
D) Undefined due to data types
Correct Answer: B) 55 as a concatenated string
Explanation: The +
operator concatenates strings. Since both '5'
and '5'
are strings, the result is '55'
.
A) var x = 5; declaration
B) define x = 5; assignment
C) initialize x with let 5
D) type x: number assign 5
Correct Answer: A) var x = 5; declaration
Explanation: In JavaScript, the var
or let
keyword is used to declare variables, followed by the assignment operator =
.
A) list() to avoid duplicates
B) {} to store unique items
C) set() to initialize values
D) dict() to define values
Correct Answer: C) set() to initialize values
Explanation: The set()
function creates a collection of unique, unordered elements. {}
is also used but can be ambiguous with empty dictionaries.
A) Mutable only stores numbers
B) Immutable changes contents
C) Mutable allows data change
D) Immutable defines a sequence
Correct Answer: C) Mutable allows data change
Explanation: Mutable data types, like lists, can be modified after creation, while immutable types, like tuples, cannot.
A) [0, 1, 2] as a sequence
B) [1, 2, 3] by increment
C) Error in argument type
D) Null for undefined range
Correct Answer: A) [0, 1, 2] as a sequence
Explanation: The range(3)
function generates numbers from 0
to 2
, and list()
converts them into a list.
A) class extends parent()
B) class derived from()
C) class child(base): define
D) class child(parent): base
Correct Answer: D) class child(parent): base
Explanation: In Python, inheritance is specified by placing the parent class name inside parentheses after the child class name.
A) Sequential data in arrays
B) Functions with no state
C) Conditional loops in logic
D) Encapsulation in methods
Correct Answer: D) Encapsulation in methods
Explanation: Object-oriented programming emphasizes encapsulation, where data and functions are bundled into objects.
A) Initialize object attributes
B) Define a method as static
C) Terminate object execution
D) Encapsulate functions safely
Correct Answer: A) Initialize object attributes
Explanation: The __init__
method is a constructor in Python, called when an object is created to initialize its attributes.
A) Use super().method()
B) Use parent.method()
C) Use child.class() method
D) Use extends.super() logic
Correct Answer: A) Use super().method()
Explanation: The super()
function allows access to methods from a superclass, enabling method overriding or augmentation.
& stay ahead of your competitors!
* Subscribe to our email newsletter to get the latest posts delivered right to your email.