1.
The following Python code – >>> 2.0 + 2
Correct Answer
C. 4.0
Explanation
The given Python code is performing addition between a float (2.0) and an integer (2). In Python, when performing arithmetic operations between different numeric types, the result will be of the more precise type. In this case, since 2.0 is a float and 2 is an integer, the result will be a float. Therefore, the correct answer is 4.0.
2.
Which of the following is true of Python but not of C or Java?
Correct Answer
A. Indentation is used for block statements.
Explanation
In Python, indentation is used to define block statements, which means that the code within a block is indented at the same level. This is not the case in C or Java, where block statements are defined using braces {}. In C and Java, line breaks are used to end a statement, while in Python, line breaks are not required to end a statement. Additionally, Python has more than two forms of looping, unlike the statement that says "Only two forms of looping are used." Therefore, the correct answer is "Indentation is used for block statements."
3.
What is the order of operation is Python?
Correct Answer
A. PEMDAS rule
Explanation
The order of operations in Python follows the PEMDAS rule, which stands for Parentheses, Exponents, Multiplication and Division (from left to right), and Addition and Subtraction (from left to right). This rule determines the sequence in which mathematical operations are performed in an expression.
4.
What is the output of >>> 5.5=5?
Correct Answer
B. Syntax Error: can't assign to literal
Explanation
The correct answer is "Syntax Error: can't assign to literal". In Python, the "=" symbol is used for variable assignment, not for comparing values. Therefore, trying to assign a value to a literal like 5.5 will result in a syntax error.
5.
What is the output of the following program?
>>> word = 'abcdefghij'
>>> print (word[:3] + word[3:])
Correct Answer
D. Abcdefghij
Explanation
The program takes a string "word" with the value "abcdefghij". It then uses slicing to concatenate the substring from index 0 to index 3 (exclusive) with the substring from index 3 to the end of the string. This essentially combines the entire string, resulting in the output "abcdefghij".
6.
What is the output of the below program?
>>> a = [4,7,3,2,5,9]
>>> a[-2]
Correct Answer
B. 5
Explanation
The program creates a list called 'a' with the elements [4,7,3,2,5,9]. The expression 'a[-2]' accesses the second element from the end of the list, which is 5. Therefore, the output of the program is 5.
7.
What is the output of the below program?
>>> 'abc' * 3
Correct Answer
B. Abcabcabc
Explanation
The output of the program is "abcabcabc". This is because the string 'abc' is multiplied by 3 using the * operator, which concatenates the string with itself three times.
8.
What is the output of the below program?
>>> S = "NCR Gurgaon"
>>> S[1:5]
Correct Answer
B. CR G
Explanation
The output of the program is "CR G". This is because the slice notation [1:5] extracts the characters from index 1 to index 4 (excluding index 5) from the string "NCR Gurgaon". Therefore, the characters "CR G" are returned as the output.
9.
Which of the following statements is true?
Correct Answer
D. All of the above.
Explanation
The statement "All of the above" is the correct answer because all three statements are true. Python is a high-level programming language, meaning it is designed to be easily readable and understandable by humans. Python is also an interpreted language, which means that it does not need to be compiled before running, allowing for faster development and testing. Additionally, Python is an object-oriented language, which means it supports the creation and manipulation of objects to solve problems. Therefore, all three statements are true.
10.
What is used to define a block of code (body of loop, function etc.) in Python?
Correct Answer
C. Indentation
Explanation
In Python, a block of code is defined using indentation. This means that instead of using curly braces or parentheses like in other programming languages, Python uses the indentation level to determine which lines of code belong to a particular block. This helps in improving code readability and ensures that the code is properly structured.