Python MCQs - Variables And Operators

This section focuses on the "Variables And Operators" of the Python programming. These Multiple Choice Questions (mcq) should be practiced to improve the Python programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which one of the following is correct way of declaring and initialising a variable, x with value 5?

A. int x
     x=5
B. int x=5
C. x=5
D. declare x=5

View Answer


2. Which of the following is not valid variable name in Python?

A. _var
B. var_name
C. var11
D. 11var

View Answer


3. Which one is false regarding local variables?

A. These can be accessed only inside owning function
B. Any changes made to local variables does not reflect outside the function.
C. These remain in memory till the program ends
D. None of the above

View Answer


4. Which one is false regarding global variables?

A. Global variables can only be read inside the function declaring the variable as global inside the function.
B. Global variables remain in memory till the end of the program
C. Global variables are those which are declared in global scope.
D. None of the above

View Answer


5. How many local and global variables are there in the following Python code?

var1=5
def fn():
var1=2
var2=var1+5
var1=10
fn()

A. 1 local, 1 global variables
B. 1 local, 2 global variables
C. 2 local, 1 global variables
D. 2 local, 2 global variables

View Answer


6. What will be the output of the following Python code?

def fn():
global var1
var1=10
var1=var1*5
print(var1)
var1=5
fn()
print(var1)

A. 25
     5
B. 50
     5
C. 25
     25
D. 50
     50

View Answer


7. What will be the output of the following Python code?

x=5
def function1():
global x
y=x+x*2
print(y)
x=7
function1()
print(x)

A. 21
     7
B. 15
     5
C. 21
     5
D. 15
     7

View Answer


8. What will be the value of variable y after execution of following Python code?

x="55"
y=x + str(9)

A. 64
B. 9
C. 559
D. Error

View Answer


9. Which of the following is incorrect regarding variables in Python?

A. Variable names in Python cannot start with number. However, it can contain number in any other position of variable name.
B. Variable names can start with an underscore.
C. Data type of variable names should not be declared
D. None of the above

View Answer


10. Which of the following will give error?

A. a=b=c=1
B. a,b,c=1
C. a,b,c=1, python, 1.5
D. None of the above

View Answer


11. How many keywords are there in python 3.7?

A. 32
B. 33
C. 31
D. 30

View Answer


12. What is the maximum length of an identifier in python?

A. 32
B. 31
C. 63
D. None of the above

View Answer


13. All keyword in python are in

A. Lowercase
B. Uppercase
C. Both uppercase & Lowercase
D. None of the above

View Answer


14. Which of the following statment is False?

A. Variable names can be arbitrarily long.
B. They can contain both letters and numbers.
C. Variable name can begin with underscore.
D. Variable name can begin with number.

View Answer


15. Which of the following is a valid variable?

A. var@
B. 32var
C. class
D. abc_a_c

View Answer


16. Why are local variable names beginning with an underscore discouraged?

A. they confuse the interpreter
B. they are used to indicate a private variables of a class
C. they are used to indicate global variables
D. they slow down execution

View Answer


17. Which of these are keyword?

A. in
B. is
C. assert
D. All of the above

View Answer


18. What is the output of the following code : print 5//2

A. 2
B. 2.5
C. 2.0
D. Error

View Answer


19. Arrange this in order of Precedence.
1. Exponentiation
2. Parentheses
3. Multiplication and Division
4. Addition and Subtraction

A. 1,2,3,4
B. 2,1,3,4
C. 1,2,4,3
D. 2,3,1,4

View Answer


20. Which of this statment will give an error?

A. a++
B. ++a
C. a+=1
D. Both A and B

View Answer


21. Which operator is used to calculate power of x raise to y.

A. x^y
B. x*y
C. x**y
D. None of the above

View Answer


22. Operators with the same precedence are evaluated from?

A. Left to Right
B. Right to Left
C. Depends on Compiler
D. None of the above

View Answer


23. "in" is a operator in python?

A. True
B. False
C. Neither true nor false
D. None of the above

View Answer


24. What will be the output of statment 2**2**2**2

A. 16
B. 256
C. 32768
D. 65536

View Answer


25. What will be the output of the following code

 a = 1
b = ++a
print(b is a)

A. True
B. False
C. Error
D. None of the above

View Answer






Also check :


Discussion



* You must be logged in to add comment.