Python Sample questions
Python Sample questions
Q1. 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
A. print(set1[0])
B. set1[0]=9
C. set1=set1+{7}
D. All of the above
14. Which one of the following has the highest precedence in the
expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
15. Which one of the following has the same precedence level?
a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication
16. Which of the following functions is a built-in function in python?
a) seed()
b) sqrt()
c) factorial()
d) print ()
A. None
B. 12
12
C. 22
22
D. 12
22
24. What will be the output of the following Python code?
def function1(var1=5, var2=7):
var2=9
var1=3
print (var1, " ", var2)
funcJon1(10,12)
A. 5 7
B. 3 9
C. 10 12
D. Error
31. If the else statement is used with a while loop, the else statement
is executed when the condition becomes _______.
A. TRUE
B. FALSE
C. Infinite
D. Null
42. list, tuple, and range are the ___ of Data Types.
A. Sequence Types
B. Binary Types
C. Boolean Types
D. None of the mentioned above
45. Amongst which of the following is / are true about the while loop?
A. It continually executes the statements as long as the given
condition is true
B. It first checks the condition and then jumps into the instructions
C. The loop stops running when the condition becomes fail, and
control will move to the next line of code.
D. All of the mentioned above