Python Programming - Data Types

Exercise : Data Types - General Questions
  • Data Types - General Questions
51.
How do you check if a variable is of type float?
isfloat(variable)
type(variable) == float
variable.is_float()
float(variable)
Answer: Option
Explanation:
The type() function is used to check the type of a variable.

52.
What is the output of the following code snippet?
my_dict = {'a': 1, 'b': 2, 'c': 3}
result = 'b' in my_dict
print(result)
True
False
2
Error
Answer: Option
Explanation:
The in keyword checks if the specified key is present in the dictionary.

53.
What is the purpose of the bool() function?
Converts a string to a boolean
Checks if a variable is of type boolean
Converts a number to a boolean
Creates a boolean variable with a specified value
Answer: Option
Explanation:
The bool() function can be used to convert a number to a boolean. 0 becomes False, and any non-zero value becomes True.

54.
What will be the result of the following code snippet?
my_string = "Python"
result = my_string.find("th")
print(result)
2
3
th
True
Answer: Option
Explanation:
The find() method returns the index of the first occurrence of the specified substring.

55.
How do you concatenate two strings?
string1.concat(string2)
string1 + string2
string1.append(string2)
concat(string1, string2)
Answer: Option
Explanation:
The '+' operator is used for string concatenation in Python.