1.
Write your text here
2.
Write your text here
3.
What is a correct syntax to output "Hello World" in Python?
Correct Answer
A. Print("Hello World")
Explanation
The correct syntax to output "Hello World" in Python is "print("Hello World")". This statement uses the print function in Python to display the specified text on the console.
4.
A string is immutable in Python? Every time when we modify the string, Python Always create a new String and assign a new string to that variable.
Correct Answer
A. True
Explanation
In Python, strings are immutable, meaning that they cannot be changed once they are created. Whenever we modify a string, Python creates a new string and assigns it to a new variable, leaving the original string unchanged. This is why the statement "Every time when we modify the string, Python always creates a new string and assigns a new string to that variable" is true.
5.
What is the output of the following code?
var1 = 1
var2 = 2
var3 = "3"
print(var + var2 + var3)
Correct Answer
D. Error. Mixing operators between numbers and strings are not supported
Explanation
The code is attempting to concatenate a number and a string, which is not supported. This results in an error.
6.
Which operator has higher precedence in the following list
Correct Answer
A. **, Exponent
Explanation
The ** operator, also known as the exponent operator, has higher precedence than the other operators in the given list. This means that any expression involving this operator will be evaluated before expressions involving the other operators.
7.
What is the output of the following code?
str = "pynative"
print (str[1:3])
Correct Answer
B. Yn
Explanation
The code is using string slicing to extract a portion of the string "pynative". The slicing syntax [1:3] means that it will start from the character at index 1 (inclusive) and go up to, but not including, the character at index 3 (exclusive). Therefore, the output will be "yn", which is the substring starting from index 1 and ending at index 2 in the original string.
8.
Which one is NOT a legal variable name?
Correct Answer
D. My-var
Explanation
The variable name "my-var" is not legal because it contains a hyphen. In most programming languages, hyphens are not allowed in variable names. Variables must typically consist of letters, numbers, and underscores, and they cannot start with a number. Therefore, "my-var" does not meet the criteria for a legal variable name.
9.
What is the output of the following code?
p, q, r = 10, 20 ,30
print(p, q, r)
Correct Answer
C. 10,20,30
Explanation
The given code assigns the values 10, 20, and 30 to the variables p, q, and r respectively. Then, it prints the values of p, q, and r which are 10, 20, and 30. Therefore, the output of the code is 10, 20, 30.
10.
What is the output of the following
x = 36 / 4 * (3 + 2) * 4 + 2
print(x)
Correct Answer
A. 182
Explanation
The correct answer is 182. This is because the expression follows the order of operations, which states that parentheses should be evaluated first, followed by multiplication and division from left to right, and finally addition and subtraction from left to right. In this case, the expression inside the parentheses, (3 + 2), evaluates to 5. Then, the division 36 / 4 is performed, resulting in 9. Next, the multiplication 9 * 5 * 4 is done, giving 180. Finally, the addition 180 + 2 is calculated, resulting in the final output of 182.
11.
Var = "KLS" * 2 * 3
print(var)
Correct Answer
A. KLSKLSKLSKLSKLSKLS
Explanation
The given code assigns the string "KLS" to the variable "var" and then multiplies it by 2 and 3. This means that the string "KLS" is repeated 2 times and then the resulting string is repeated 3 times. The final output is "KLSKLSKLSKLSKLSKLS".
12.
Can we use the “else” clause for loops?
for example:
for i in range(1, 5):
print(i)
else:
print("this is else block statement" )
Correct Answer
A. Yes
Explanation
Yes, we can use the "else" clause for loops. In this example, the loop iterates over the range from 1 to 5. After the loop completes all iterations, the "else" block is executed, and the statement "this is else block statement" is printed. The "else" clause in a loop is executed only if the loop completes all iterations without encountering a "break" statement.
13.
What is the output of the following code?
listOne = [20, 40, 60, 80]
listTwo = [20, 40, 60, 80]
print(listOne == listTwo)
print(listOne is listTwo)
Correct Answer
B. True
False
Explanation
The output of the code is "True" and "False". The first print statement compares the values of the two lists, so it returns True because the values in both lists are the same. The second print statement uses the "is" operator to check if the two lists are the same object in memory, which is not the case here, so it returns False.
14.
How do you create a variable with the floating number 2.8?
Correct Answer
C. Both the other answers are correct
Explanation
The correct answer is that both the other answers are correct. This means that you can create a variable with the floating number 2.8 by either using the float() function or directly assigning the value 2.8 to the variable. Both methods will result in the variable holding the floating number 2.8.
15.
What is the correct syntax to output the type of a variable or object in Python?
Correct Answer
A. Print(type(x))
Explanation
The correct syntax to output the type of a variable or object in Python is "print(type(x))". This will print the type of the variable or object stored in the variable "x".
16.
What is the correct way to create a function in Python?
Correct Answer
C. Def myFunction():
Explanation
The correct way to create a function in Python is by using the "def" keyword followed by the function name and parentheses. This is the standard syntax for defining a function in Python.
17.
What is a correct syntax to return the first character in a string?
Correct Answer
B. X = "Hello"[0]
Explanation
The correct syntax to return the first character in a string is "x = "Hello"[0]". This syntax uses indexing to access the first character of the string "Hello". The index 0 represents the first character in the string.
18.
Which method can be used to return a string in upper case letters?
Correct Answer
A. Upper()
Explanation
The correct answer is "upper()". This method can be used to return a string in upper case letters.
19.
Which method can be used to replace parts of a string?
Correct Answer
B. Replace()
Explanation
The method "replace()" can be used to replace parts of a string. This method takes two parameters: the substring to be replaced and the substring to replace it with. It searches for all occurrences of the substring in the given string and replaces them with the new substring. This method is commonly used for tasks such as replacing certain characters or words within a string.
20.
Which of these collections defines a LIST?
Correct Answer
D. ["apple", "banana", "cherry"]
Explanation
The correct answer is [ "apple", "banana", "cherry" ] because it is enclosed in square brackets, which is the syntax for defining a list in many programming languages. Lists are ordered collections of items, and in this case, the list contains three strings: "apple", "banana", and "cherry". The other options are not valid syntax for defining a list.
21.
Which of these collections defines a TUPLE?
Correct Answer
A. ("apple", "banana", "cherry")
Explanation
A tuple is defined by using parentheses, as shown in the correct answer. The other options use square brackets, curly braces, or a combination of curly braces and colons, which are not the correct syntax for defining a tuple.
22.
Which of these collections defines a SET?
Correct Answer
D. {"apple", "banana", "cherry"}
Explanation
The correct answer is {"apple", "banana", "cherry"}. This is because a set is an unordered collection of unique elements, and the given collection only contains unique elements and is enclosed in curly braces, which is the syntax for defining a set in many programming languages. The other options either contain duplicate elements or use different syntax, making them incorrect.
23.
Which collection is ordered, changeable, and allows duplicate members?
Correct Answer
A. LIST
Explanation
A list is an ordered collection in Python that allows duplicate elements and is changeable, meaning that elements can be added, removed, or modified. This makes it the correct answer for the given question. Sets, dictionaries, and tuples have different characteristics and do not meet all the requirements mentioned in the question.
24.
How do you start writing an if statement in Python?
Correct Answer
B. If x > y:
Explanation
The correct answer is "if x > y:". In Python, an if statement is started by using the keyword "if" followed by the condition that needs to be evaluated. The condition in this case is "x > y", which checks if the value of x is greater than the value of y. The colon at the end of the line indicates the start of the code block that will be executed if the condition is true.
25.
Which statement is used to stop a loop?
Correct Answer
B. Break
Explanation
The correct answer is "break". In programming, the "break" statement is used to terminate a loop prematurely. When the "break" statement is encountered within a loop, the loop is immediately exited, and the program continues executing from the next line after the loop. This is useful when a certain condition is met, and you want to stop the loop from further iterations.
26.
What is the output of the following code
salary = 8000
def printSalary():
salary = 12000
print("Salary:", salary)
printSalary();
print("Salary:", salary)
Correct Answer
B. Salary: 12000 Salary: 8000
Explanation
The code defines a variable "salary" with a value of 8000. Then, a function "printSalary()" is defined, which creates a new variable "salary" with a value of 12000 and prints it. When the function is called, it prints "Salary: 12000". After that, outside of the function, the original variable "salary" with a value of 8000 is printed, resulting in "Salary: 8000". Therefore, the output of the code is "Salary: 12000 Salary: 8000".