1. Which of these in not a core data type?
a) Lists
b) Dictionary
c) Tuples
d) Class
Discussion
Explanation: Class is a user defined data type.
2. 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
Discussion
Explanation: Python shell throws a NoneType object back.
3. 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
Discussion
Explanation: Python codes have to be indented properly.
4. Which of the following will run without errors?
a) round(45.8)
b) round(6352.898,2,5)
c) round()
d) round(7463.123,2,1)
Discussion
Explanation: Execute help(round) in the shell to get details of the parameters that are passed into the round function.
5. What is the return type of function id?
a) int
b) float
c) bool
d) dict
Discussion
Explanation: Execute help(id) to find out details in python shell.id returns a integer value that is unique.
6. In python we do not specify types, it is directly interpreted by the compiler, so consider the following operation to be performed.
>>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
d) All of the mentioned
Discussion
Explanation: // is integer operation in python 3.0 and int(..) is a type cast operator.
7. What data type is the object below?
L = [1, 23, 'hello', 1]
a) list
b) dictionary
c) array
d) tuple
Discussion
Explanation: List data type can store any values within it.
8. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
Discussion
Explanation: Dictionary stores values in terms of keys and values.
9. Which of the following results in a SyntaxError?
a) ‘”Once upon a time…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”’
Discussion
Explanation: Carefully look at the colons.
10. What is the return value of trunc()?
a) int
b) bool
c) float
d) None
Discussion
Explanation: Execute help(math.trunc) to get details.