0% found this document useful (0 votes)
2 views3 pages

Python Test Questions

The document contains a series of Python test questions covering various topics such as anonymous functions, list filtering, set operations, and dictionary manipulations. It includes multiple-choice questions, code snippets, and true/false statements to assess knowledge of Python programming. Additionally, it prompts for explanations and function writing related to Python concepts.

Uploaded by

vibingqueen2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python Test Questions

The document contains a series of Python test questions covering various topics such as anonymous functions, list filtering, set operations, and dictionary manipulations. It includes multiple-choice questions, code snippets, and true/false statements to assess knowledge of Python programming. Additionally, it prompts for explanations and function writing related to Python concepts.

Uploaded by

vibingqueen2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Python test questions

1.Python supports the creation of anonymous functions at runtime, using a construct called __________
a) pi
b) anonymous
c) lambda
d) none of the mentioned

2.What will be the output of the following Python code?

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

a) [1, 0, 2, ‘hello’, ”, []]


b) Error
c) [1, 2, ‘hello’]
d) [1, 0, 2, 0, ‘hello’, ”, []

3. What will be the output of the following Python function?

min(max(False,-3,-4), 2,7)

a) -4
b) -3
c) 2
d) False

4.What will be the output of the following Python code?

x = 'abcd'for i in x:

print(i.upper())

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

6.What will be the output of the following Python program?

z=set('abc')

z.add('san')

z.update(set(['p', 'q']))

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}

7.What will be the value of ‘result’ in following Python program?

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)

a) [1, 3, 5, 7, 8]
b) [1, 7, 8]
c) [1, 2, 4, 7, 8]
d) error

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

>>>"Welcome to Python".split()

a) [“Welcome”, “to”, “Python”]


b) (“Welcome”, “to”, “Python”)
c) {“Welcome”, “to”, “Python”}
d) “Welcome”, “to”, “Python”

9.What will be the output of the following Python code snippet?

numbers = {}

letters = {}
comb = {}

numbers[1] = 56

numbers[3] = 7

letters[4] = 'B'

comb['Numbers'] = numbers

comb['Letters'] = lettersprint(comb)

a) Error, dictionary in a dictionary can’t exist


b) ‘Numbers’: {1: 56, 3: 7}
c) {‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}}
d) {‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}

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

test = {1:'A', 2:'B', 3:'C'}del test[1]test[1] = 'D'del test[2]print(len(test))

a) 0
b) 2
c) Error as the key-value pair of 1:’A’ is already deleted
d) 1

11.What will be the output of the following Python code?

def change(i = 1, j = 2):

i = i + j

j = j + 1

print(i, j)

change(j = 1, i = 2)

a) An exception is thrown because of conflicting values


b) 1 2
c) 3 3
d) 3 2

12. The one’s complement of 110010101 is:


a) 001101010
b) 110010101
c) 001101011
d) 110010100

13.Which of the following is invalid?


a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned

14. of the following is an invalid statement?


a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
15. What does 3 ^ 4 evaluate to?
a) 81
b) 12
c) 0.75
d) 7

16. What will be the output of the following Python code?

l=[1,2,3,4,5][x&1 for x in l]

a) [1, 1, 1, 1, 1]
b) [1, 0, 1, 0, 1]
c) [1, 0, 0, 0, 0]
d) [0, 1, 0, 1, 0]

17. Which of these in not a core data type?


a) Lists
b) Dictionary
c) Tuples
d) Class

18. Explain the difference between mutable and immutable types in Python.
Give examples of each.

19. What is the difference between is and ==?

20. Write a function to check if a number is prime

21. Write a function to reverse a string.

22. Explain string slicing with an example

True or false questions

23. Python uses curly braces {} to define code blocks.


24. In Python, you can reassign a variable to a value of a different data type.
25. The elif keyword is used to add more conditions to an if-else statement.
26. Sets allow duplicate elements.
27. A while loop will always execute at least once.
28. Dictionary keys must be unique.
29. Print numbers from 100 to 10.
30. Write a program to find reverse in string.

You might also like