1. What is the output of print(2 ** 3 ** 2)
64
512
2. What is the output of print(2%6)
ValueError
0.33
2
3. Bitwise shift operators (<<, >>) has higher precedence than Bitwise And(&)
operator
False
True
4. What is the output of the following addition (+) operator
a = [10, 20]
b = a
b += [30, 40]
print(a)
print(b)
[10, 20, 30, 40]
[10, 20, 30, 40]
[10, 20]
[10, 20, 30, 40]
5. What is the output of print(2 * 3 ** 3 * 4)
216
864
6. What is the output of print(10 - 4 * 2)
2
12
7. 4 is 100 in binary and 11 is 1011. What is the output of the following bitwise
operators?
a = 4
2. b = 11
print(a | b)
print(a >> 2)
15
1
14
1
8. What is the output of the expression print(-18 // 4)
-4
4
-5
5
9. What is the output of the following code
print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
True True False True
False True True True
True True False True
False True False True
10. What is the value of the following Python Expression
print(36 / 4)
9.0
9
11. Whichof the following operators has the highest precedence?
not
&
*
+
12. What is the output of the following code
x = 6
y = 2
3. print(x ** y)
print(x // y)
66
0
36
0
66
3
36
3
13. What is the output of the following assignment operator
y = 10
x = y += 2
print(x)
12
10
SynatxError
14. What is the output of the following Python code
x = 10
y = 50
if (x ** 2 > 100 and y < 100):
print(x, y)
100 500
10 50
None
15. What is the output of the following code
x = 100
y = 50
print(x and y)
True
100
False
50
4. Whichmethod should I use to convert String "welcome to the beautiful world
of python" to "Welcome To The Beautiful World Of Python"
capitalize()
title()
2. Select the correct output of the following String operations
strOne = str("pynative")
strTwo = "pynative"
print(strOne == strTwo)
print(strOne is strTwo)
false false
true true
true false
false true
3. Select the correct output of the following String operations
str1 = 'Welcome'
print (str1[:6] + ' PYnative')
Welcome PYnative
WelcomPYnative
Welcom PYnative
WelcomePYnative
4. Select the correct output of the following String operations
str = "my name is James bond";
print (str.capitalize())
My Name Is James Bond
TypeError: unsupported operand type(s) for * or pow(): ‘str’ and ‘int’
My name is james bond
5. Select the correct output of the following String operations
str1 = "my isname isisis jameis isis bond";
sub = "is";
print(str1.count(sub, 4))
5
5. 6
7
6. Choose the correct function to get the ASCII code of a character
char(‘char’)
ord(‘char’)
ascii(‘char’)
7. Select the correct output of the following String operations
myString = "pynative"
stringList = ["abc", "pynative", "xyz"]
print(stringList[1] == myString)
print(stringList[1] is myString)
true false
true true
8. Guess the correct output of the following code?
str1 = "PYnative"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
PYn PYnat ive PYnativ vitanYP
Yna PYnat tive PYnativ vitanYP
Yna PYnat tive PYnativ PYnativ
9. Guess the correct output of the following String operations
str1 = 'Welcome'
print(str1*2)
WelcomeWelcome
TypeError: unsupported operand type(s) for * or pow(): ‘str’ and ‘int’
10. What is the output of the following string operations
str = "My salary is 7000";
print(str.isalnum())
True
False
6. 11. Python does not support a character type; a single character is treated as
strings of length one.
False
True
12. What is the output of the following code
str1 = "My salary is 7000";
str2 = "7000"
print(str1.isdigit())
print(str2.isdigit())
False
True
False
False
True
False
13. Strings are immutable in Python, which means a string cannot be modified.
True
False
14. What is the output of the following string comparison
print("John" > "Jhon")
print("Emma" < "Emm")
True
False
False
False
15. Choose the correctfunction to get the character from ASCII number
ascii(‘number)
char(number)
chr(number)
Select which is true for for loop
7. Python’s for loop used to iterates over the items of list, tuple, dictionary, set,
or string
else clause of for loop is executed when the loop terminates naturally
else clause of for loop is executed when the loop terminates abruptly
Weuse for loop when we want to perform a task indefinitely until a particular
condition is met
2. What is the output of the following nested loop
for num in range(10, 14):
for i in range(2, num):
if num%i == 1:
print(num)
break
10
11
12
13
11
13
3. What is the value of x
x = 0
while (x < 100):
x+=2
print(x)
101
99
None of the above, this is an infinite loop
100
4. What is the output of the following range() function
for num in range(2,-5,-1):
print(num, end=", ")
2, 1, 0
2, 1, 0, -1, -2, -3, -4, -5
2, 1, 0, -1, -2, -3, -4
5. What is the output of the following for loop and range() function
8. for num in range(-2,-5,-1):
print(num, end=", ")
-2, -1, -3, -4
-2, -1, 0, 1, 2, 3,
-2, -1, 0
-2, -3, -4,
6. What is the output of the following loop
for l in 'Jhon':
if l == 'o':
pass
print(l, end=", ")
J, h, n,
J, h, o, n,
7. Given the nested if-else structure below, what will be the value of x after
code execution completes
x = 0
a = 0
b = -5
if a > 0:
if b < 0:
x = x + 5
elif a > 5:
x = x + 4
else:
x = x + 3
else:
x = x + 2
print(x)
2
0
3
4
8. What is the value of x after the following nested for loop completes its
execution
x = 0
for i in range(10):
for j in range(-1, -10, -1):
x += 1
9. print(x)
99
90
100
9. What is the output of the following if statement
a, b = 12, 5
if a + b:
print('True')
else:
print('False')
False
True
10. What is the value of the var after the for loop completes its execution
var = 10
for i in range(10):
for j in range(2, 10, 1):
if var % 2 == 0:
continue
var += 1
var+=1
else:
var+=1
print(var)
20
21
10
30
11. if -3 will evaluate to true
True
False
12. Given the nested if-else below, what will be the value x when the code
executed successfully
x = 0
a = 5
b = 5
10. if a > 0:
if b < 0:
x = x + 5
elif a > 5:
x = x + 4
else:
x = x + 3
else:
x = x + 2
print(x)
0
4
2
3
13. What is the output of the following nested loop
numbers = [10, 20]
items = ["Chair", "Table"]
for x in numbers:
for y in items:
print(x, y)
10 Chair
10 Table
20 Chair
20 Table
10 Chair
10 Table
In Python3, Whatever you enter as input, the input() function converts it into a
string
False
True
2. Whichof the following is incorrect file handling mode in Python
r
x
t+
b
3. Whichof the following is incorrect file handling mode in Python
11. wb+
ab
xr
ab+
4. What is the output of print('[%c]' % 65)
65
A
[A]
Syntax Error
5. Use the following file to predict the output of the code
test.txt Content:
aaa
bbb
ccc
ddd
eee
fff
ggg
Code:
f = open("test.txt", "r")
print(f.readline(3))
f.close()
bbb
Syntax Error
aaa
aa
6. In Python3, which functions are used to accept input from the user
input()
raw_input()
rawinput()
string()
7. What is the output of the following print() function
12. print(sep='--', 'Ben', 25, 'California')
Syntax Error
Ben–25–California
Ben 25 California
8. What will be displayed as an output on the screen
x = float('NaN')
print('%f, %e, %F, %E' % (x, x, x, x))
nan, nan, NAN, NAN
nan, NaN, nan, NaN
NaN, NaN, NaN, NaN,
9. What is true for file mode x
create a file if the specified file does not exist
Create a file, returns an error if the file exists
Create a file if it doesn’t exists else Truncate the existed file
10. What is the output of print('%x, %X' % (15, 15))
15 15
F F
f f
f F
11. What is the output of the following print() function
print('%d %d %.2f' % (11, '22', 11.22))
11 22 11.22
TypeError
11 ’22’ 11.22
12. What is the output of the following code
print('PYnative ', end='//')
print(' is for ', end='//')
print(' Python Lovers', end='//')
13. PYnative /
is for /
Python Lovers /
PYnative //
is for //
Python Lovers //
PYnative // is for // Python Lovers//
PYnative / is for / Python Lovers/