Python Variables and Data Types (Multiple Choice Questions) MCQ – Python Interview objective questions| Python Quiz

21. If x=3.123, then int(x) will give ?

  1. 3.1
  2. 0
  3. 1
  4. 3

Answer : D
Explanation: int() will convert the float value into integer value.

22. Which of the following is the example of typecasting?

  1. int(5)
  2. str(5)
  3. str(xyz)
  4. All of the above

Answer : D
Explanation: All

23. What is type casting in python?

  1. Declaration of data type
  2. Destroy data type
  3. Change data type property
  4. None of the above

Answer : C
Explanation: Type casting means changing the property of data types.

24. In Python 3, the maximum value for an integer is 263 – 1:

  1. True
  2. Flase

Answer : B
Explanation: In Python 2, there was an internal limit to how large an integer value could be. But that limit was removed in Python 3.
This means there is no explicitly defined limit, but the amount of available address space forms a practical limit depending on the machine Python runs on.

25. Which of the following is not a data type in python?

  1. List
  2. Tuple
  3. Dictionary
  4. Book

Answer : D
Explanation: Book is not a data type

26. Which of the following is a valid way to specify the string literal foo'bar in Python:

  1. “foo’bar”
  2. ‘foo”bar’
  3. ‘foo’bar’
  4. None of the above

Answer : A

27. Correct way to declare a variable x of float data type in python:

  1. x = 2.5
  2. float x = 2.5
  3. float(2.5)
  4. All of the above

Answer : A
Explanation: We just write the variable name and can assign any type of value and then the type of variable will change according to the value we assign in it.

28. All keywords in Python are in ____

  1. None of the below
  2. lower case
  4. Capitalized

Answer : A
Explanation: True, False, and None are capitalized while the others are in lower case.

29. Which of the following is true for variable names in Python?

  1. Underscore and ampersand are the only two special characters allowed
  2. All private members must have leading and trailing underscores
  3. Unlimited length
  4. none of the mentioned

Answer : C
Explanation: Variable names can be of any length.

30. What does ~4 evaluate to?

  1. -4
  2. -5
  3. -3
  4. +3

Answer : B
Explanation: ~x is equivalent to -(x+1).

31. In order to store values in terms of key and value we use that core data type in python?

  1. List
  2. Class
  3. Dictionary
  4. Tupple

Answer : C
Explanation: Dictionary is the collection of keys and their value.

32. How can we get 6 from the given list: list=[9,5,6,3]

  1. list[-2]
  2. list[-1]
  3. list[3]
  4. None of the above

Answer : A
Explanation: list[-2] will give the second last element of the list.

This Post Has 5 Comments

Leave a Reply