Python Quizs Question and Answers – Core Data Types

Q 1. Which of these in not a core data type?
A. Lists
B. Dictionary
C. Tuples
D. Class

Show Answer Answer:-D. Class
Explanation Explanation:- Class is a user defined data type.

Q 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

Show Answer Answer:-D. None
Explanation Explanation:- Python shell throws a NoneType object back.

Q 3. What will be the output of the following Python code?

  1. >>>str=”hello”
  2. >>>str[:2]
  3. >>>

A. he
B. lo
C. olleh
D. hello

Show Answer Answer:-A. he
Explanation Explanation:- We are printing only the 1st two bytes of string and hence the answer is “he”.

Q 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)

Show Answer Answer:-A. round(45.8)
Explanation Explanation:- Execute help(round) in the shell to get details of the parameters that are passed into the round function.

Q 5. What is the return type of function id?
A. int
B. float
C. bool
D. dict

Show Answer Answer:-A. int
Explanation Explanation:- Execute help(id) to find out details in python shell.id returns a integer value that is unique.

Q 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

Show Answer Answer:-D. All of the mentioned
Explanation Explanation:- // is integer operation in python 3.0 and int(..) is a type cast operator.

Q 7. What error occurs when you execute the following Python code snippet?

apple = mango

A. SyntaxError
B. NameError
C. ValueError
D. TypeError

Show Answer Answer:-B. NameError
Explanation Explanation:- Mango is not defined hence name error.

Q 8. What will be the output of the following Python code snippet?

  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

Show Answer Answer:-B. cannot perform mathematical operation on strings
Explanation Explanation:- Python codes have to be indented properly.

Q 9. What data type is the object below?

L = [1, 23, 'hello', 1]

A. list
B. dictionary
C. array
D. tuple

Show Answer Answer:-A. list
Explanation Explanation:- List data type can store any values within it.

Q 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

Show Answer Answer:-D. dictionary
Explanation Explanation:- Dictionary stores values in terms of keys and values.

11. 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”’

Show Answer Answer:-C. ‘3\’
Explanation Explanation:- Carefully look at the colons.

Q 12. The following is displayed by a print function call. Select all of the function calls that result in this output.

  1. tom
  2. dick
  3. harry

A.print(”’tom
\ndick
\nharry”’)

B. print(”’tomdickharry”’)
C. print(‘tom\ndick\nharry’)
D. print(‘tom
dick
harry’)

Show Answer Answer:-C. print(‘tom\ndick\nharry’)
Explanation Explanation:- The \n adds a new line.

Q 13. What is the average value of the following Python code snippet?

  1. >>>grade1 = 80
  2. >>>grade2 = 90
  3. >>>average = (grade1 + grade2) / 2

A. 85.0
B. 85.1
C. 95.0
D. 95.1

Show Answer Answer:-A. 85.0
Explanation Explanation:- Cause a decimal value of 0 to appear as output.

Q 14. 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 Answer:-C. print(‘hello-‘ + ‘how-are-you’)
Explanation Explanation:- Execute in the shell.

Q 15. What is the return value of trunc()?
A. int
B. bool
C. float
D. None

Show Answer Answer:-A. int
Explanation Explanation:- Execute help(math.trunc) to get details.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page