Python Programming MCQ - Variables And Operators

13. 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


14. 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


15. 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


16. 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


17. 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


18. 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


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.