Test Series - python

Test Number 3/108

Q: What will be the output of the following Python code?

>>>str="hello"
>>>str[:2]
>>>
A. he
B. lo
C. olleh
D. hello
Solution: We are printing only the 1st two bytes of string and hence the answer is “he”.
Q: 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
Solution: Python shell throws a NoneType object back.
Q: Which of these in not a core data type?
A. Lists
B. Dictionary
C. Tuples
D. Class
Solution: Class is a user defined data type.
Q: 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)
Solution: Execute help(round) in the shell to get details of the parameters that are passed into the round function.
Q: What is the return type of function id?
A. int
B. float
C. bool
D. dict
Solution: Execute help(id) to find out details in python shell.id returns a integer value that is unique.
Q: 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
Solution: // is integer operation in python 3.0 and int(..) is a type cast operator.
Q: What error occurs when you execute the following Python code snippet?

apple = mango
A. SyntaxError
B. NameError
C. ValueError
D. TypeError
Solution: Mango is not defined hence name error.
Q: 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
Solution: Dictionary stores values in terms of keys and values.

You Have Score    /8