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
πŸ’¬ Discuss
βœ… Correct Answer: (D) all of the mentioned

Explanation: // is integer operation in python

Q. 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
πŸ’¬ Discuss
βœ… Correct Answer: (A) indentation error

Explanation: python codes have to be indented properly.

Q. What data type is the object below? L = [1, 23, 'hello', 1]

  • (A) list
  • (B) dictionary
  • (C) array
  • (D) tuple
πŸ’¬ Discuss
βœ… Correct Answer: (A) list

Explanation: list data type can store any

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
πŸ’¬ Discuss
βœ… Correct Answer: (D) dictionary

Explanation: dictionary stores values in terms of keys and values.

Q. 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”’
πŸ’¬ Discuss
βœ… Correct Answer: (C) ‘3\\’

Explanation: carefully look at the colons.

Q. 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
πŸ’¬ Discuss
βœ… Correct Answer: (A) 85.0

Explanation: cause a decimal value of 0 to appear as output.

Q. What is the return value of trunc()?

  • (A) int
  • (B) bool
  • (C) float
  • (D) none
πŸ’¬ Discuss
βœ… Correct Answer: (A) int

Explanation: execute help(math.trunc) to get details.

Q. What is the output of print 0.1 + 0.2 == 0.3?

  • (A) true
  • (B) false
  • (C) machine dependent
  • (D) error
πŸ’¬ Discuss
βœ… Correct Answer: (B) false

Explanation: neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. the round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.

Q. Which of the following is not a complex number?

  • (A) k = 2 + 3j
  • (B) k = complex(2, 3)
  • (C) k = 2 + 3l
  • (D) k = 2 + 3j
πŸ’¬ Discuss
βœ… Correct Answer: (C) k = 2 + 3l

Explanation: l (or l) stands for long.

Q. What is the type of inf?

  • (A) boolean
  • (B) integer
  • (C) float
  • (D) complex
πŸ’¬ Discuss
βœ… Correct Answer: (C) float

Explanation: infinity is a special case of floating point numbers. it can be obtained by float(‘inf’).

Jump to