Python Programming - Data Types
Exercise : Data Types - General Questions
- Data Types - General Questions
41.
What is the purpose of the
count()
method in Python lists?Answer: Option
Explanation:
The count()
method is used to count the number of occurrences of a specified element in a list.
Here is an example program that uses the count() method:
list = [1, 2, 3, 4, 1, 2]
print(list.count(1))
This program will print the number 2, which is the number of times the element 1 appears in the list.
42.
What will be the output of the following code snippet?
my_dict = {'a': 1, 'b': 2, 'c': 3}
result = my_dict.get('d', 'Not Found')
print(result)
Answer: Option
Explanation:
The
get()
method returns the value for the specified key. If the key is not found, it returns the default value, which is 'Not Found'
in this case.
43.
How do you convert a string to lowercase?
Answer: Option
Explanation:
The
lower()
method is used to convert a string to lowercase in Python.
44.
What is the output of the following code snippet?
my_set = {1, 2, 3, 4, 5}
my_set.remove(3)
print(my_set)
Answer: Option
Explanation:
The
remove()
method is used to remove a specific element from a set.
45.
What is the purpose of the
chr()
function?
Answer: Option
Explanation:
The
chr()
function returns a string representing a character whose Unicode code point is the integer.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers