3-Core Data Types
3-Core Data Types
a) Lists
b) Dictionary
c) Tuples
d) Class
Answer: d
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
Answer: d
Explanation: Python shell throws a NoneType object back.
1. >>>str="hello"
2. >>>str[:2]
3. >>>
a) he
b) lo
c) olleh
d) hello
Answer: a
Explanation: We are printing only the 1st two bytes of string and hence the answer is “he”.
Answer: a
Explanation: Execute help(round) in the shell to get details of the parameters that are passed into
the round function.
6. In python we do not specify types, it is directly interpreted by the compiler, so consider the
following operation to be performed.
1. >>>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
Answer: d
Explanation: // is integer operation in python 3.0 and int(..) is a type cast operator.
7. What error occurs when you execute the following Python code snippet?
apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
Answer: b
Explanation: Mango is not defined hence name error.
1. def example(a):
2. a = a + '2'
3. a = a*2
4. return a
5. >>>example("hello")
a) indentation Error
b) cannot perform mathematical operation on strings
c) hello2
d) hello2hello2
Answer: a
Explanation: Python codes have to be indented properly.
a) list
b) dictionary
c) array
d) tuple
Answer: a
Explanation: List data type can store any values within it.
10. 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
Answer: d
Explanation: Dictionary stores values in terms of keys and values.
Answer: c
Explanation: Carefully look at the colons.
12. 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')
Answer: c
Explanation: The \n adds a new line.
13. What is the average value of the following Python code snippet?
1. >>>grade1 = 80
2. >>>grade2 = 90
a) 85.0
b) 85.1
c) 95.0
d) 95.1
Answer: a
Explanation: Cause a decimal value of 0 to appear as output.
hello-how-are-you
Answer: c
Explanation: Execute in the shell.
Answer: a
Explanation: Execute help(math.trunc) to get details.