Correct Answer: A) 2 for integer division
Explanation: The //
operator performs floor division, discarding the fractional part. Dividing 5
by 2
gives 2
.
A) 4 times in total
B) 5 times in total
C) Infinite due to error
D) Once for every element
Correct Answer: B) 5 times in total
Explanation: The range(5)
function generates numbers from 0
to 4
, so the loop executes 5 times, printing each value.
A) 2 for integer division
B) 2.5 for floating result
C) 0 due to truncation
D) Error in syntax use
Correct Answer: A) 2 for integer division
Explanation: The //
operator performs floor division, discarding the fractional part. Dividing 5
by 2
gives 2
.
A) class for structure
B) def for declaration
C) struct for data
D) object for templates
Correct Answer: A) class for structure
Explanation: The class
keyword in Python defines a blueprint for creating objects, encapsulating methods and attributes.
A) (key1:value1, key2:value2)
B) [key1:value1, key2:value2]
C) {key1:value1, key2:value2}
D) <key1:value1, key2:value2>
Correct Answer: C) {key1:value1, key2:value2}
Explanation: Dictionaries in Python use curly braces {}
to store key-value pairs, separated by a colon :
.
A) Assigns values to variables
B) Compares identity of objects
C) Defines scope in a block
D) Checks for membership
Correct Answer: B) Compares identity of objects
Explanation: The is
operator checks whether two variables point to the same object in memory, not just their values.
A) Indicates block of code
B) Adds comments in loops
C) Separates multiple lines
D) Specifies logical errors
Correct Answer: A) Indicates block of code
Explanation: Python uses indentation to define blocks of code, such as those in loops, functions, and conditionals, instead of braces.
A) define my_function() {pass}
B) function my_function(): pass
C) def my_function(): pass
D) func my_function {return;}
Correct Answer: C) def my_function(): pass
Explanation: Python functions are defined using the def
keyword, followed by the function name, parentheses, and a colon.
A) False because types differ
B) Cannot evaluate condition
C) Error in type coercion
D) True because values match
Correct Answer: D) True because values match
Explanation: In most languages, 5
(integer) and 5.0
(float) are considered equal because their values are equivalent.
A) int[][] arr = new int[3][3];
B) int arr[3][3] = new int;
C) int arr = [3][3] integers;
D) int new array[3][3];
Correct Answer: A) int[][] arr = new int[3][3];
Explanation: In Java, a 2D array is declared using double square brackets [][]
followed by memory allocation with new
.
A) break
continues execution; return
halts all code
B) break
exits loops; return
exits functions
C) break
skips lines; return
changes logic
D) break
modifies loops; return
accesses variables
Correct Answer: B) break
exits loops; return
exits functions
Explanation: The break
statement exits a loop, while return
exits a function and optionally returns a value.
A) let declaration keyword
B) def declaration keyword
C) init declaration keyword
D) var declaration keyword
Correct Answer: D) var declaration keyword
Explanation: In JavaScript, var
and let
are commonly used to declare variables, with let
being the modern preference.
A) error for debug tools
B) catch for conditions
C) try for error handling
D) block for secure access
Correct Answer: C) try for error handling
Explanation: The try
keyword is used to define a block of code where exceptions might occur, typically followed by catch
or finally
.
A) array.length property
B) size(array) function
C) array.count property
D) getSize(array) function
Correct Answer: A) array.length property
Explanation: The .length
property is widely used in many programming languages to find the number of elements in an array.
A) By starting with an underscore _
B) By using all-uppercase names
C) By ending with a semicolon ;
D) By using angle brackets < >
Correct Answer: A) By starting with an underscore _
Explanation: In many languages like Python, private variables are indicated by a single or double underscore prefix, though true enforcement depends on the language.
A) Float is immutable
B) String is immutable
C) Tuple is immutable
D) List is mutable type
Correct Answer: D) List is mutable type
Explanation: Lists in Python can be modified after creation, while strings, tuples, and numbers are immutable.
A) ;; for single-line comment
B) // for single-line comment
C) # for single-line comment
D) ** for single-line comment
Correct Answer: C) # for single-line comment
Explanation: In Python, single-line comments start with a #
symbol, and the interpreter ignores the text following it.
A) Error in logical syntax
B) True is the output
C) Null for invalid logic
D) False is the output
Correct Answer: D) False is the output
Explanation: The not
operator inverts a boolean value. Since True
is inverted, the result is False
.
A) “”” for multiple lines
B) <<EOF for multiple lines
C) {} brackets for strings
D) using backticks “
Correct Answer: A) “”” for multiple lines
Explanation: Multi-line strings in Python are enclosed in triple quotes ("""
or '''
), allowing the string to span multiple lines.
A) for is used in Python
B) iter() is used in Python
C) range() is used in Python
D) map() is used in Python
Correct Answer: B) iter() is used in Python
Explanation: The iter()
function creates an iterator object, allowing sequential access to elements in a collection.
A) Skips a specific iteration
B) Terminates the program
C) Restarts the current loop
D) Defines an empty block
Correct Answer: D) Defines an empty block
Explanation: The pass
statement in Python acts as a placeholder for code that is syntactically required but not yet implemented.
& stay ahead of your competitors!
* Subscribe to our email newsletter to get the latest posts delivered right to your email.