Python Data Types Questions and Answers

Practice Mode
Showing 10 of 24 questions
Q11
How do you check if a key exists in a dictionary?
  • A has_key()
  • B contains()
  • C in
  • D exists()
Answer: Option C
Explanation: The 'in' keyword is used to check for key existence in dictionaries.
Q12
What is the output of: print(10 // 3)
  • A 3.333
  • B 3
  • C 4
  • D 3.0
Answer: Option B
Explanation: Floor division (//) returns the largest integer less than or equal to the result.
Q13
Which data type preserves order and allows duplicates?
  • A set
  • B dictionary
  • C list
  • D frozenset
Answer: Option C
Explanation: Lists maintain insertion order and allow duplicate elements.
Q14
What is the result of: bool(0)
  • A True
  • B False
  • C Error
  • D None
Answer: Option B
Explanation: In Python, zero values are considered False in boolean context.
Q15
Which method adds an element to the end of a list?
  • A insert()
  • B add()
  • C push()
  • D append()
Answer: Option D
Explanation: append() adds a single element to the end of a list.
Q16
What is the data type of range(5)?
  • A list
  • B tuple
  • C range
  • D generator
Answer: Option C
Explanation: The range() function returns a range object, not a list.
Q17
Which operator is used for string repetition?
  • A +
  • B *
  • C x
  • D repeat()
Answer: Option B
Explanation: The asterisk (*) operator repeats strings when used with a string and integer.
Q18
What does the get() method do for dictionaries?
  • A Adds a new key-value pair
  • B Returns value for key, or default if not found
  • C Removes a key-value pair
  • D Checks if key exists
Answer: Option B
Explanation: The get() method returns None or a default value if the key is not found, avoiding KeyError.
Q19
Which of these is a floating point number?
  • A 5
  • B 5.0
  • C "5"
  • D [5]
Answer: Option B
Explanation: Numbers with decimal points are float type in Python.
Q20
What is the result of: "hello"[1:4]
  • A hel
  • B ell
  • C ello
  • D hell
Answer: Option B
Explanation: String slicing returns a substring from start index up to but not including end index.
Questions and Answers for Competitive Exams Various Entrance Test