0% found this document useful (0 votes)
8 views4 pages

Set 1 PWP

The document consists of a series of Python programming questions, each with multiple-choice answers. The questions cover various topics including loops, expressions, functions, and data structures in Python. It tests the reader's understanding of Python syntax and behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Set 1 PWP

The document consists of a series of Python programming questions, each with multiple-choice answers. The questions cover various topics including loops, expressions, functions, and data structures in Python. It tests the reader's understanding of Python syntax and behavior.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

‭1. What will be the output of the following Python code?


‭i = 1‬
‭while True:‬
‭if i % 3 == 0:‬
‭break‬
‭print(i, end=" ")‬
‭i += 1‬
‭a) 1 2 3‬
‭b) error‬
‭c) 1 2‬
‭d) none of the mentioned‬

‭2. What will be the value of the following Python expression?‬


‭4 + 3 % 5‬
‭a) 7‬
‭b) 2‬
‭c) 4‬
‭d) 1‬

‭3. What will be the output of the following Python code snippet if x = 1?‬
‭x << 2‬
‭a) 4‬
‭b) 2‬
‭c) 1‬
‭d) 8‬

‭4. What are the values of the following Python expressions?‬


‭2 ** (3 ** 2)‬
‭(2 ** 3) ** 2‬
‭2 ** 3 ** 2‬

‭ ) 512, 64, 512‬


a
‭b) 512, 512, 512‬
‭c) 64, 512, 64‬
‭d) 64, 64, 64‬

‭5. What will be the output of the following Python code?‬


‭l = [1, 0, 2, 0, 'hello', '', []]‬
‭list(filter(bool, l))‬

‭ ) [1, 0, 2, 'hello', '', []]‬


a
‭b) Error‬
‭c) [1, 2, 'hello']‬
‭d) [1, 0, 2, 0, 'hello', '', []]‬
‭6. What will be the output of the following Python function?‬
‭min(max(False, -3, -4), 2, 7)‬
‭a) -4‬
‭ ) -3‬
b
‭c) 2‬
‭d) False‬

‭7. What will be the output of the following Python expression if x = 56.236?‬
‭print("%.2f" % x)‬

‭ ) 56.236‬
a
‭b) 56.23‬
‭c) 56.0000‬
‭d) 56.24‬

‭8. What will be the output of the following Python code?‬


‭x = 'abcd'‬
‭for i in x:‬
‭print(i.upper())‬
‭a) a B C D‬
‭b) a b c d‬
‭c) error‬
‭d) A B C D‬

‭9. What will be the output of the following Python code snippet?‬
‭for i in [1, 2, 3, 4][::-1]:‬
‭print(i, end=' ')‬
‭a) 4 3 2 1‬
‭b) error‬
‭c) 1 2 3 4‬
‭d) none of the mentioned‬

‭10. What will be the output of the following Python code?‬


‭def addItem(listParam):‬
‭listParam += [1]‬
‭mylist = [1, 2, 3, 4]‬
‭addItem(mylist)‬
‭print(len(mylist))‬

‭ ) 5‬
a
‭b) 8‬
‭c) 2‬
‭d) 1‬
‭11. What will be the output of the following Python statement? "a" + "bc"‬
‭a) bc‬
‭b) abc‬
‭c) a‬
‭d) bca‬

‭12. What will be the output of the following Python code?‬


‭class tester:‬
‭def __init__(self, id):‬
‭self.id = str(id)‬
‭id = "224"‬
‭temp = tester(12)‬
‭print(temp.id)‬
‭a) 12‬
‭b) 224‬
‭c) None‬
‭d) Error‬

‭13. What will be the output of the following Python program?‬


‭def foo(x):‬
‭x[0] = ['def']‬
‭x[1] = ['abc']‬
‭return id(x)‬
‭q = ['abc', 'def']‬
‭print(id(q) == foo(q))‬
‭a) Error‬
‭b) None‬
‭c) False‬
‭d) True‬

‭14. What will be the output of the following Python program?‬


‭z = set('abc')‬
‭z.add('san')‬
‭z.update(set(['p', 'q']))‬
‭print(z)‬
‭a) {'a', 'c', 'c', 'p', 'q', 's', 'a', 'n'}‬
‭b) {'abc', 'p', 'q', 'san'}‬
‭c) {'a', 'b', 'c', 'p', 'q', 'san'}‬
‭d) {'a', 'b', 'c', ['p', 'q'], 'san'}‬

‭15. What will be the output of the following Python code?‬


‭print("abc. DEF".capitalize())‬
‭a) Abc. def‬
‭b) abc. def‬
‭c) Abc. Def‬
‭d) ABC. DEF‬
‭16. What will be the output of the following Python code?‬
‭print('*', "abcde".center(6), '*', sep='')‬
‭a) * abcde *‬
‭b) *abcde *‬
‭c) * abcde*‬
‭d) * abcde *‬

‭17. What will be the output of the following Python code?‬


‭list1 = [1, 2, 3, 4]‬
‭list2 = list1‬
‭list1[0] = 4‬
‭print(list2)‬
‭a) [1, 4]‬
‭b) [1, 3, 4]‬
‭c) [4, 3]‬
‭d) [4, 2, 3, 4]‬

‭18. Which of the following Python statements will result in the output: 6?‬
‭A = [[1, 2, 3],‬
‭[4, 5, 6],‬
‭[7, 8, 9]]‬
‭a) A[2][1]‬
‭b) A[1][2]‬
‭c) A[3][2]‬
‭d) A[2][3]‬

‭19. What will be the output of the following Python code?‬


‭x = 'abcd'‬
‭for i in range(len(x)):‬
‭print(i)‬

‭ ) error‬
a
‭b) 1 2 3 4‬
‭c) a b c d‬
‭d) 0 1 2 3‬

‭20. What will be the output of the following Python code snippet?‬
‭z = set('abc$de')‬
‭print('a' in z)‬

‭ ) Error‬
a
‭b) True‬
‭c) False‬
‭d) No output‬

You might also like