Learn Python and related technologies

Python Variables and Data Types Quiz


Test and reinforce your understanding of Python variables and data types with this interactive quiz.

Question 1.

What is the correct way to declare a variable in Python?





Question 2.

Which of the following is not a built-in data type?





Question 3.

What is the output of the following code?

x = "5"
y = 10

print(x + y)





Question 4.

Which of the following is true about Python variables?





Question 5.

What is the output of the following code?

a = True
b = False

print(a + b)





Question 6.

How can you check the data type of a variable x?





Question 7.

What is the output of the following code?

x = 2 + 3j

print( type(x) )





Question 8.

Which of the following is not a valid variable name?





Question 9.

What will be the output of the following code?

x = "hello"
y = 3

print(x * y)





Question 10.

What is the output of the following code?

x = "Python"

print( x[1] )





Question 11.

What is the default data type of a variable assigned using a decimal value?

x = 4.5





Question 12.

Which of the following is not a correct way to create a string?





Question 13.

What is the output of the following code?

x = 10
y = x
x = 20

print(y)





Question 14.

Which of the following data types is immutable?





Question 15.

Which of the following objects can be used as dictionary keys?





Question 16.

What is the output of the following code?

x = 20

def func():
    x = 50

print(x)



Question 17.

Which of the following keywords can be used to alter the scope of a variable?





Question 18.

What is the output of the following code?

x = 20

def func():
    global x
    x = 50

func()

print( x )





Question 19.

What is the output of the following code?

float('nan') == float('nan')




Question 20.

What is the output of the following code?

a, *b, c = ['Python', 'Java', 'C++', 'Ruby']

print( b )