Exercises on Python Data Types

The following exercises cover scenarios on data types in Python.

Exercise 1

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

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

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

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

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

Code copied to clipboard successfully 👍