21). Which of these in not a core data type?
[A]Lists
[B]Dictionary
[C]Tuples
[D]Class
Show Answer
Correct Answer: Class
Notes:
Answer: d
Explanation: Class is a user defined data type.
22). Given a function that does not return any value, What value is thrown by default when executed in shell.
[A]int
[B]bool
[C]void
[D]None
Show Answer
Correct Answer: None
Notes:
Answer: d
Explanation: Python shell throws a NoneType object back.
23). What will be the output of the following Python code?
>>>str="hello"
>>>str[:2]
>>>
[A]he
[B]lo
[C]olleh
[D]hello
Show Answer
Correct Answer: he
Notes:
Answer: a
Explanation: We are printing only the 1st two bytes of string and hence the answer is “he”.
24). Which of the following will run without errors?
>>>str="hello"
>>>str[:2]
>>>
[A]round(45.8)
[B]round(6352.898,2,5)
[C]round()
[D]round(7463.123,2,1)
Show Answer
Correct Answer: round(45.8)
Notes:
Answer: a
Explanation: Execute help(round) in the shell to get details of the parameters that are passed into the round function.
25). What is the return type of function id?
>>>str="hello"
>>>str[:2]
>>>
[A]int
[B]float
[C]bool
[D]dict
Show Answer
Correct Answer: int
Notes:
Answer: a
Explanation: Execute help(id) to find out details in python shell.id returns a integer value that is unique.
26). In python we do not specify types, it is directly interpreted by the compiler, so consider the following operation to be performed. objective is to make sure x has a integer value, select all that apply (python 3.xx)
>>>x = 13 ? 2
[A]x = 13 // 2
[B]x = int(13 / 2)
[C]x = 13 % 2
[D]All of the mentioned
Show Answer
Correct Answer: All of the mentioned
Notes:
Answer: d
Explanation: // is integer operation in python 3.0 and int(..) is a type cast operator.
27). What error occurs when you execute the following Python code snippet?
apple = mango
[A]SyntaxError
[B]NameError
[C]ValueError
[D]TypeError
Show Answer
Correct Answer: NameError
Notes:
Answer: b
Explanation: Mango is not defined hence name error.
28). What will be the output of the following Python code snippet?
def example(a):
a = a + '2'
a = a*2
return a
>>>example("hello")
[A]indentation Error
[B]cannot perform mathematical operation on strings
[C]hello2
[D]hello2hello2
Show Answer
Correct Answer: indentation Error
Notes:
Answer: a
Explanation: Python codes have to be indented properly.
29). What data type is the object below?
L = [1, 23, 'hello', 1]
[A]list
[B]dictionary
[C]array
[D]tuple
Show Answer
Correct Answer: list
Notes:
Answer: a
Explanation: List data type can store any values within it.
30). In order to store values in terms of key and value we use what core data type.
L = [1, 23, 'hello', 1]
[A]list
[B]tuple
[C]class
[D]dictionary
Show Answer
Correct Answer: dictionary
Notes:
Answer: d
Explanation: Dictionary stores values in terms of keys and values.
31). Which of the following results in a SyntaxError?
L = [1, 23, 'hello', 1]
[A]‘”Once upon a time…”, she said.’
[B]“He said, ‘Yes!'”
[C] ‘3\’
[D] ”’That’s okay”’
Show Answer
Correct Answer: ‘3\’
Notes:
Answer: c
Explanation: Carefully look at the colons.
32). The following is displayed by a print function call. Select all of the function calls that result in this output.
tom
dick
harry
[A] print('''tom \ndick \nharry''')
[B]print(”’tomdickharry”’)
[C]print(‘tom\ndick\nharry’)
[D]print('tom dick harry')
Show Answer
Correct Answer: print(‘tom\ndick\nharry’)
Notes:
Answer: c
Explanation: The \n adds a new line.
33). What is the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
[A]85.0
[B]85.1
[C]95.0
[D]95.1
Show Answer
Correct Answer: 85.0
Notes:
Answer: a
Explanation: Cause a decimal value of 0 to appear as output.
34). Select all options that print.
hello-how-are-you
[A]print(‘hello’, ‘how’, ‘are’, ‘you’)
[B]print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
[C]print(‘hello-‘ + ‘how-are-you’)
[D]print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)
Show Answer
Correct Answer: print(‘hello-‘ + ‘how-are-you’)
Notes:
Answer: c
Explanation: Execute in the shell.
35). What is the return value of trunc()?
hello-how-are-you
[A]int
[B]bool
[C]float
[D]None
Show Answer
Correct Answer: int
Notes:
Answer: a
Explanation: Execute help(math.trunc) to get details.