MCQ PRECTISE QUESTIONS

1.       What is a variable in Python?

        a. A constant

        b. A reserved word

        c. A named location in memory used to store data

        d. A function in Python

 

2.       How do you assign a value to a variable in Python?

a. assign variable_name = value

b. set variable_name to value

c. variable_name -> value

d. variable_name = value

 

3.       What is the data type of the variable in Python determined by?

a. The programmer's preference

b. The variable name

c. The value it holds

d. The size of the variable

 

4.       Which of the following is a valid variable name in Python?

a. 2nd_variable

b. my_variable@123

c. totalAmount

d. class

 

5.       What happens if you try to use a variable that has not been assigned a value?

a. It results in a syntax error.

b. It automatically assigns the value None.

c. It prompts the user to enter a value.

d. It raises a runtime error.

 

6.       Which of the following is an example of a string variable in Python?

a. 42

b. 3.14

c. "Hello, World!"

d. True

 

7.       In Python, how do you change the value of an existing variable?

a. Reassign a new value using =

b. Use the change() function

c. Call the modify() method

d. Use the update keyword

 

8.       What is the convention for naming constants in Python?

a. UPPERCASE_WITH_UNDERSCORES

b. camelCase

c. lowercase_with_underscores

d. PascalCase

 

9.       How do you assign values to multiple variables in a single line?

a. a = b = c = 10

b. a, b, c = 10

c. a = 10, b = 10, c = 10

d. a = b, c = 10

 

10.    What is the purpose of using docstrings for variables?

a. To declare variables

b. To provide documentation for the variable

c. To indicate a constant value

d. To specify the variable's data type