The following exercises cover scenarios on data types in Python.
Exercise 1 – Built-in function to get type
What is the built-in function that returns the type of the given value or variable.
We have a print statement that ought to print the data type of x
. Insert the built-in function that returns the type of x.
x = 'apple' print((x))
Exercise 2 – Data type of ‘apple’
We have a variable x
assigned with a string value. What would be the type of x
?
x = 'apple' print(type(x)) #Output :
Exercise 3 – Data type of 3.14
We have a variable x
assigned with a floating point number. What would be the type of x
?
x = 3.14 print(type(x)) #Output :
Exercise 4 – Data type of [2, 4, 6, 8]
We have a variable named x
which is assigned a list of some numbers. What would be the type of x
?
x = [2, 4, 6, 8] print(type(x)) #Output :
Exercise 5 – Data type of 5 + 3.14
We have a variable named x
which is assigned an integer, and a variable y
which is assigned with a floating point number. We find the sum of these two numbers, and store the result in variable z
. Then we print the data type of variable z using type() built-in function. What would be the type of z
?
x = 5 y = 3.14 z = x + y print(type(z)) #Output :
References