Python Programming - Data Types

Exercise : Data Types - General Questions
  • Data Types - General Questions
31.
Which of the following data types is mutable?
int
float
str
list
Answer: Option
Explanation:
Lists in Python are mutable, meaning their elements can be changed after the list is created.

32.
What is the purpose of the type() function?
To convert a variable to a different data type
To check the data type of a variable
To perform mathematical operations
To round a floating-point number
Answer: Option
Explanation:
The type() function is used to determine the type of a variable.

33.
What is the output of the following code snippet?
my_list = [1, 2, 3, 4, 5]
print(my_list[1:4])
[2, 3, 4]
[1, 2, 3]
[1, 2, 3, 4]
[3, 4, 5]
Answer: Option
Explanation:
Slicing is used to extract a portion of a list. The specified range is [1:4], which includes elements at indices 1, 2, and 3.

34.
How do you convert a floating-point number to an integer?
int(x)
convert(x, int)
x.integer()
round(x)
Answer: Option
Explanation:
The int() function can be used to convert a floating-point number to an integer by truncating the decimal part.

35.
What is the purpose of the append() method in Python lists?
To remove an element from the list
To add an element to the end of the list
To add an element at a specified position
To check if an element is present in the list
Answer: Option
Explanation:
The append() method is used to add an element to the end of a list.