[go: up one dir, main page]

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

Set 2 - PWP

The document contains a series of multiple-choice questions related to Python programming, covering topics such as function definitions, output of code snippets, and data types. Each question provides four answer options, with some questions focusing on specific Python functions and their behavior. The document serves as a quiz or test for assessing knowledge of Python programming concepts.
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)
4 views4 pages

Set 2 - PWP

The document contains a series of multiple-choice questions related to Python programming, covering topics such as function definitions, output of code snippets, and data types. Each question provides four answer options, with some questions focusing on specific Python functions and their behavior. The document serves as a quiz or test for assessing knowledge of Python programming concepts.
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

‭ . What will be the output of the following Python expression?


1
‭round(4.576)‬
‭a) 4‬
‭b) 4.6‬
‭c) 5‬
‭d) 4.5‬

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


2
‭print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))‬
‭a) Hello ('foo', 'bin') and ('foo', 'bin')‬
‭b) Error‬
‭c) Hello foo and bin‬
‭d) None of the mentioned‬

‭ . What is the output of print(math.pow(3, 2))?‬


3
‭a) 9.0‬
‭b) None‬
‭c) 9‬
‭d) None of the mentioned‬

‭ . The process of pickling in Python includes:‬


4
‭import pickle‬
‭data = {'a': 1, 'b': 2}‬
‭pickled_data = pickle.dumps(data)‬
‭a) conversion of a Python object hierarchy into byte stream‬
‭b) conversion of a datatable into a list‬
‭c) conversion of a byte stream into Python object hierarchy‬
‭d) conversion of a list into a datatable‬

‭ . What will be the value of 'result' in the following Python program?‬


5
‭list1 = [1, 2, 3, 4]‬
‭list2 = [2, 4, 5, 6]‬
‭list3 = [2, 6, 7, 8]‬
‭result = list()‬
‭result.extend(i for i in list1 if i not in (list2 + list3) and i not in result)‬
‭result.extend(i for i in list2 if i not in (list1 + list3) and i not in result)‬
‭result.extend(i for i in list3 if i not in (list1 + list2) and i not in result)‬
‭print(result)‬
‭a) [1, 3, 5, 7, 8]‬
‭b) [1, 7, 8]‬
‭c) [1, 2, 4, 7, 8]‬
‭d) error‬

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


6
‭def f(x, y, z):‬
‭return x + y + z‬
‭ rint(f(*[1, 2, 3]))‬
p
‭a) Error‬
‭b) [1, 2, 3]‬
‭c) 6‬
‭d) None‬

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


7
‭a = [1, 2, 3, 4]‬
‭b = [sum(a[0:x+1]) for x in range(0, len(a))]‬
‭print(b)‬
‭a) [1, 3, 6, 10]‬
‭b) [1, 2, 3, 4]‬
‭c) [0, 1, 3, 6]‬
‭d) Error‬

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


8
‭def foo(i, x=[]):‬
‭x.append(i)‬
‭return x‬
‭for i in range(3):‬
‭print(foo(i), end=" ")‬
‭a) [0] [1] [2]‬
‭b) [0] [0, 1] [0, 1, 2]‬
‭c) [0, 1, 2]‬
‭d) Error‬

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


9
‭def multipliers():‬
‭return [lambda x: i * x for i in range(4)]‬
‭print([m(2) for m in multipliers()])‬
‭a) [0, 2, 4, 6]‬
‭b) [0, 2, 4, 8]‬
‭c) [6, 6, 6, 6]‬
‭d) [8, 8, 8, 8]‬

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


1
‭numbers = [10, 20]‬
‭items = ["Chair", "Table"]‬
‭for x in numbers:‬
‭for y in items:‬
‭print(x, y)‬
‭a) 10 Chair, 10 Table, 20 Chair, 20 Table‬
‭b) 10 Chair 10 Table 20 Chair 20 Table‬
‭c) Error‬
‭d) None of the mentioned‬
‭ 1. What is the output of the following code snippet?‬
1
‭print(bool("False"))‬
‭a) False‬
‭b) True‬
‭c) 0‬
‭d) Error‬

‭ 2. Which of the following is the correct syntax for defining a function in Python?‬
1
‭a) function foo():‬
‭b) def foo():‬
‭c) define foo():‬
‭d) function foo[]:‬

‭ 3. What is the output of this Python code?‬


1
‭print(type(lambda: None))‬
‭a) <class 'function'>‬
‭b) <type 'lambda'>‬
‭c) <function>‬
‭d) <class 'lambda'>‬

‭ 4. Which of the following is used to define a block of code in Python?‬


1
‭a) Curly braces {}‬
‭b) Parentheses ()‬
‭c) Indentation‬
‭d) Quotation marks‬

‭ 5. What is the output of the following code?‬


1
‭a = [1, 2, 3]‬
‭print(a * 2)‬
‭a) [1, 2, 3, 1, 2, 3]‬
‭b) [2, 4, 6]‬
‭c) Error‬
‭d) None‬

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


1
‭print("abc DEF".swapcase())‬
‭a) ABC def‬
‭b) abc DEF‬
‭c) Abc Def‬
‭d) aBC def‬

‭ 7. What is the output of the following Python expression?‬


1
‭' '.join(['Python', 'is', 'awesome'])‬
‭a) Pythonisawesome‬
‭b) Python is awesome‬
‭c) Python, is, awesome‬
‭d) ['Python', 'is', 'awesome']‬

‭ 8. What is the result of this operation?‬


1
‭'5' * 3‬
‭a) 15‬
‭b) 555‬
‭c) Error‬
‭d) 5‬

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


1
‭a = {}‬
‭a[1] = 1‬
‭a['1'] = 2‬
‭a[1] += 1‬
‭print(a[1])‬
‭a) 1‬
‭b) 2‬
‭c) 3‬
‭d) Error‬

‭ 0. Which of the following is not a valid Python data type?‬


2
‭a) list‬
‭b) tuple‬
‭c) array‬
‭d) dictionary‬

You might also like