1.
Is Python case sensitive when dealing with identifiers?
Correct Answer
A. Yes
Explanation
Python is case sensitive when dealing with identifiers. This means that the uppercase and lowercase letters are considered as distinct characters. For example, variables named "myVariable" and "myvariable" are treated as two different variables in Python. Therefore, it is important to be consistent with the casing of identifiers while coding in Python.
2.
Which of the following is an invalid variable?
Correct Answer
B. 1st_string
Explanation
The variable "1st_string" is invalid because variable names cannot start with a number in most programming languages. Variable names must start with a letter or an underscore.
3.
All keywords in Python are in?
Correct Answer
D. None of the mentioned
Explanation
In Python, keywords are reserved words that have predefined meanings and cannot be used as variable names or identifiers. They are always written in lowercase. Therefore, the correct answer is "lower case."
4.
Which of the following is an invalid statement?
Correct Answer
B. a b c = 1000 2000 3000
Explanation
The statement "a b c = 1000 2000 3000" is an invalid statement because variable names cannot contain spaces.
5.
Which is the correct operator for power(x^y)?
Correct Answer
B. X**y
Explanation
The correct operator for power(x^y) is X**y. This is the exponentiation operator in Python, which raises the value of x to the power of y. It is commonly used to perform calculations involving exponentiation. The other options mentioned (X^y and X^^y) are not valid operators for exponentiation in Python.
6.
Which one of these is floor division?
Correct Answer
B. //
Explanation
The double forward slash (//) is the floor division operator in Python. Floor division returns the largest whole number that is less than or equal to the division of two numbers. It discards the decimal part of the result and only returns the integer value. This is different from the regular division operator (/) which returns a floating-point number. The percent sign (%) is the modulus operator, used to calculate the remainder of a division operation. Therefore, the correct answer is // as it represents floor division.
7.
What is the answer to this expression, 22 % 3 is?
Correct Answer
B. 1
Explanation
The expression 22 % 3 represents the remainder when 22 is divided by 3. In this case, 22 can be divided by 3 evenly with a remainder of 1. Therefore, the answer to the expression 22 % 3 is 1.
8.
Which one of the following has the highest precedence in the expression?
Correct Answer
D. Parentheses
Explanation
Parentheses have the highest precedence in an expression. This means that any operations within parentheses should be performed first before any other operations in the expression. This is because parentheses are used to group certain parts of an expression together, indicating that those operations should be done first. By giving parentheses the highest precedence, it ensures that the operations within them are prioritized and evaluated before any other operations in the expression.
9.
Following a set of commands are executed in shell, what will be the output?
-
>>>str="hello"
-
>>>str[:2]
-
>>>
Correct Answer
A. He
Explanation
The output will be "he" because the command "str[:2]" is slicing the string "hello" from index 0 to index 2 (exclusive), which gives us the substring "he".
10.
Carefully observe the code and give the answer.
-
def example(a):
-
a = a + '2'
-
a = a*2
-
return a
-
>>>example("hello")
Correct Answer
A. Indentation Error
Explanation
The code is missing proper indentation. This results in an indentation error when the code is executed.
11.
The following is displayed by a print function call:
-
tom
-
dick
-
harry
Select all of the function calls that result in this output
Correct Answer
C. Print(‘tom\ndick\nharry’)
Explanation
The correct answer is print(‘tomdickharry’). This function call includes line breaks (\n) between each name, resulting in each name being displayed on a separate line.
12.
What is the average value of the code that is executed below?
-
>>>grade1 = 80
-
>>>grade2 = 90
-
>>>average = (grade1 + grade2) / 2
Correct Answer
B. 85.1
Explanation
The given code calculates the average value of two grades, grade1 and grade2. It adds the two grades together and then divides the sum by 2. Therefore, the average value is 85.1.
13.
What is the result of cmp(3, 1)?
Correct Answer
A. 1
Explanation
The result of cmp(3, 1) is 1 because cmp() is a built-in function in Python that compares two objects and returns -1 if the first object is less than the second, 0 if they are equal, and 1 if the first object is greater than the second. In this case, 3 is greater than 1, so the result is 1.
14.
What is the type of inf?
Correct Answer
B. Integer
Explanation
The correct answer is integer because "inf" is a common abbreviation for infinity, which is a concept in mathematics. In programming, infinity is often represented as a special value of the data type float or double. However, in this case, the question specifically asks for the "type" of inf, and since inf is not a variable or a specific value, it doesn't have a data type. Therefore, the answer is integer because inf is not a boolean, float, or complex number.
15.
What is the output of the following?True = False
while True:
print(True)
break
Correct Answer
C. None
Explanation
The output of the given code is "None". This is because the code assigns the value of False to the variable True, which is not allowed in Python. However, since the code breaks out of the while loop immediately after the first iteration, the print statement is never executed. Therefore, there is no output and the value of the code is None.
16.
What is the output of the following?x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
Correct Answer
A. [‘ab’, ‘cd’].
Explanation
The output of the code is [‘ab’, ‘cd’] because the code is iterating over each element in the list x and applying the upper() method to each element. However, the upper() method returns a new string with all lowercase characters converted to uppercase, but it does not modify the original string. Therefore, the original list x remains unchanged and the output is still [‘ab’, ‘cd’].
17.
What is the output of the following?x = 'abcd'
for i in x:
print(i.upper())
Correct Answer
B. A B C D
Explanation
The given code iterates through each character in the string 'abcd' and prints the uppercase version of each character. So, the output will be 'A B C D'.
18.
What is the output of the following?x = 'abcd'
for i in range(len(x)):
print(i)
Correct Answer
B. 0 1 2 3
Explanation
The output of the given code is 0 1 2 3.
The code initializes a variable x with the string 'abcd'. It then iterates over the range of the length of x, which is 4 in this case. During each iteration, it prints the value of i, which starts from 0 and goes up to 3. Therefore, the output will be 0 1 2 3, each value on a separate line.
19.
What is the output of the following?for i in range(2.0):
print(i)
Correct Answer
C. error
Explanation
The code will throw an error because the range() function does not accept float values as arguments. The range() function can only accept integer values.
20.
What is the output when following statement is executed ?- >>>"a"+"bc"
Correct Answer
D. Abc
Explanation
The output of the given statement "a" + "bc" is "abc". This is because the "+" operator is used for concatenation in Python, which means it combines two strings together. In this case, the string "a" is combined with the string "bc" to form the resulting string "abc".
21.
What arithmetic operators cannot be used with strings ?
Correct Answer
C. -
Explanation
The arithmetic operator "-" cannot be used with strings. This is because the "-" operator is used for subtraction and it does not have any meaning when applied to strings. Strings can be concatenated using the "+" operator, repeated using the "*" operator, but subtraction is not a valid operation for strings.
22.
What is the output when following code is executed ?- >>> str1 = 'hello'
- >>> str1[-1:]
Correct Answer
D. O
Explanation
The code is using negative indexing to access the last character of the string "hello". The syntax str1[-1:] means to start from the last character and go until the end of the string. Therefore, the output will be "o", which is the last character of the string "hello".
23.
What is the output when following statement is executed ?- >>>print('new' 'line')
Correct Answer
A. Error
Explanation
The given statement will output "new line". This is because the print function will print the string 'new' and then move to a new line to print the string 'line'. Therefore, the output will be "new line".
24.
What is the output when following code is executed ?- >>>str1="helloworld"
- >>>str1[::-1]
Correct Answer
A. Dlrowolleh
Explanation
The given code is using slicing with a step value of -1 to reverse the string "helloworld". When a negative step value is used, the slicing starts from the end of the string and goes towards the beginning. So, the output of the code will be "dlrowolleh", which is the reversed version of "helloworld".
25.
What is the output of the following code ?- >>>example = "snow world"
- >>>example[3] = 's'
- >>>print example
Correct Answer
C. Error
Explanation
The code will produce an error. This is because strings in Python are immutable, meaning they cannot be changed once they are created. Therefore, trying to assign a new value to a specific index of a string will result in an error.
26.
What is the output of the following code ?- >>>example = "snow world"
- >>>print("%s" % example[4:7])
Correct Answer
A. Wo
Explanation
The code is using string slicing to extract a portion of the "example" string starting from index 4 and ending at index 7 (exclusive). In the "example" string, the characters at index 4, 5, and 6 are "w", "o", and "r" respectively. So, the output will be "wo".
27.
What is the output of the following code ?- >>>max("what are you")
Correct Answer
D. Y
Explanation
The code is attempting to find the maximum value in the string "what are you". However, since the max() function is being used on a string, it will return the character with the highest ASCII value, which in this case is "y".
28.
Given a string example=”hello” what is the output of example.count(l)
Correct Answer
A. 2
Explanation
The output of example.count(l) is 2 because the count() method in Python returns the number of occurrences of a specified substring in a string. In this case, "l" appears twice in the string "hello".
29.
What is the output of the following code ?- >>>example = "helle"
- >>>example.find("e")
Correct Answer
C. 1
Explanation
The output of the code is 1. The find() method in Python returns the index of the first occurrence of the specified substring within the given string. In this case, the substring "e" is found at index 1 in the string "helle". Therefore, the output is 1.
30.
Which of the following function checks in a string that all characters are whitespaces?
Correct Answer
C. Isspace()
Explanation
The function isspace() is used to check whether all characters in a string are whitespaces. It returns True if all characters are whitespaces, otherwise, it returns False. This function is useful when we want to validate if a string contains only spaces or not.
31.
Which of the following data types is not supported in python?
Correct Answer
C. Generics
Explanation
Generics is not a supported data type in Python. Generics are commonly used in statically typed languages like Java and C# to define classes, interfaces, or methods that can work with different types of data. However, Python is a dynamically typed language, which means that variables can hold values of any type without explicitly specifying the type. Therefore, generics are not necessary in Python and are not supported as a built-in data type.
32.
Which of the following is correct about Python?
Correct Answer
C. Both
Explanation
Python supports automatic garbage collection, which means that the memory management is handled automatically by the language itself. This helps in freeing up memory that is no longer in use, making the programming process more efficient and less prone to memory leaks. Additionally, Python can be easily integrated with various other programming languages and technologies such as C, C++, COM, ActiveX, CORBA, and Java. This allows developers to leverage existing code and libraries in their Python projects, making it a versatile and flexible language for software development.
33.
Which of the following is correct about Python?
Correct Answer
D. All of the above.
Explanation
Python is a versatile programming language that is high-level, interpreted, interactive, and object-oriented. It is designed to prioritize readability, using English keywords instead of punctuation and having fewer syntactical constructions compared to other languages. Therefore, all of the statements provided are correct about Python.
34.
Which of the following expressions is an example of type conversion?
Correct Answer
A. 4.0 + float(3)
Explanation
The expression 4.0 + float(3) is an example of type conversion because the integer 3 is being explicitly converted to a float using the float() function. This allows for the addition of a float (4.0) and an integer (3) by converting the integer to a float before performing the addition operation.
35.
What is the value of the expression:float(4+int(2.39)%2)
Correct Answer
C. 4.0
Explanation
The expression first calculates the value of int(2.39) which is 2. Then it calculates 4 + 2 % 2 which is equal to 4. Finally, the float() function is used to convert the result to a floating-point number, resulting in 4.0.
36.
Which of the following expressions results in an error?
Correct Answer
D. Int(’10.8’)
Explanation
The expression int('10.8') results in an error because the int() function is used to convert a value to an integer, but '10.8' is a string that cannot be directly converted to an integer.
37.
Who created Python?
Correct Answer
A. Guido van Rossam
Explanation
Guido van Rossum is the creator of Python. He developed the programming language in the late 1980s and released the first version in 1991. Python was designed to be easy to read and write, with a focus on simplicity and code readability. It has since become one of the most popular programming languages in the world, known for its versatility and extensive libraries.
38.
Python programs are executed by:
Correct Answer
A. Interpreter
Explanation
Python programs are executed by an interpreter. An interpreter is a program that reads and executes code line by line. It translates the code into machine language instructions and immediately executes them. This allows for a more interactive and flexible programming experience, as the interpreter can execute code on the go and provide immediate feedback. In contrast, a compiler translates the entire code into machine language instructions before execution, resulting in a standalone executable file. An assembler, on the other hand, is used for low-level programming languages like assembly language.
39.
If there is a ___ error in the program, it will run without generating error messages but it will not give the desired result.
Correct Answer
A. Semantic error
Explanation
A semantic error is a type of error in programming where the code is syntactically correct but does not produce the desired result. This means that the program will run without any error messages, but the output or behavior of the program will be incorrect. In other words, there is a logical mistake in the code that leads to incorrect execution. Therefore, if there is a semantic error in the program, it will run without generating error messages but will not give the desired result.
40.
Which one of the following is used for indexing in the python program?
Correct Answer
A. Brackets [ ]
Explanation
Brackets [ ] are used for indexing in a Python program. In Python, indexing is used to access individual elements or a range of elements in a sequence like a string, list, or tuple. By using brackets [ ] with an index value inside, we can retrieve the desired element from the sequence. The index value starts from 0 for the first element, and negative indexing can also be used to access elements from the end of the sequence. Therefore, the correct answer is brackets [ ].