Python Question Bank
Python Question Bank
SYLLABUS
UNIT:1 (08 Hours)
Introduction: Installation, First Python Program: Interactive Mode Programming, Script Mode
Programming; Identifiers, Reserved Words, Lines and Indentation, Multi-Line Statements,
Quotation & Comments; Assigning Values to Variables, Multiple Assignment.
Standard Data Types: Numbers, Strings, Lists, Tuples, Dictionary; Data Type Conversion;
Basic Operators: Arithmetic, Comparison, Assignment, Bitwise; Operators: Logical,
Membership, Identity; Operators Precedence; Python Numbers & Mathematical functions,
Python Strings.
Multi Choice Question of UNIT I:
1. Which of these in not a core data type?
a) Lists b) Dictionary
c) Tuples d) Class
2. What will be the output of the following Python code?
>>>str="hello"
>>>str[:2]
>>>
a) he b)lo
c) olleh d) hello
3. What data type is the object below?
L = [1, 23, 'hello', 1]
a) list b) dictionary
c) array d) tuple
4. Which of the following results in a SyntaxError?
a) ‘”Once upon a time…”, she said.’ b) “He said, ‘Yes!'”
c) ‘3\’ d) ”’That’s okay”’
5. What is the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
a) 85.0 b ) 85.1
c) 95.0 d) 95.1
6. What is the type of infinite?
a) Boolean b) Integer
c) Float d) Complex
7. Which of the following is incorrect?
a) x = 0b101 b) x = 0x4f5
c) x = 19023 d) x = 03964
8. What does 3 ^ 4 evaluate to?
a) 81 b) 12
c) 0.75 d) 7
9. What will be the value of the following Python expression?
4+3%5
a) 4 b) 7
c) 2 d) 0
10. What is the value of the following expression?
8/4/2, 8/(4/2)
a) (1.0, 4.0) b) (1.0, 1.0)
c) (4.0. 1.0) d) (4.0, 4.0)
11. What is the value of the following expression?
float(22//3+3/3)
a) 8 b) 8.0
c) 8.3 d) 8.33
12. Is Python case sensitive when dealing with identifiers?
a) yes b) no
c) machine dependent d) none of the mentioned
13. What is the maximum possible length of an identifier?
a) 31 characters b) 63 characters
c) 79 characters d) none of the mentioned
14. Which of the following is an invalid variable?
a) my_string_1 b) 1st_string
c) foo d) _
15. Which of the following is not a keyword?
a) eval b) assert
c) nonlocal d) pass
16. Which 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
17. What will be the output of the following Python expression if x=15 and y=12?
x&y
a) b1101 b) 0b1101
c) 12 d) 1101
18. What will be the output of the following Python expression?
0x35 | 0x75
a) 115 b) 116
c) 117 d) 118
19. What will be the value of the following Python expression?
bin(10-2)+bin(12^4)
a) 0b10000 b) 0b10001000
c) 0b1000b1000 d) 0b10000b1000
20. What will be the output of the ~100 Python expression?
a) 101 b) -101
c) 100 d) -100
Short Type Questions of UNITS I:
1. What is the difference between list and tuples in Python?
2. What are the key features of Python?
3. What type of language is python? Programming or scripting?
4. How is Python an interpreted language?
5. What is pep 8?
6. How is memory managed in Python?
7. What are python modules? Name some commonly used built-in modules in Python?
8. What are local variables and global variables in Python?
9. What is type conversion in Python?
10. Is indentation required in python?
11. What is the difference between Python Arrays and lists?
12. What are the built-in types of python?
13. Explain the need for Unicodes.
Long Type Questions of Unit I:
1. Explain the different string formats available in Python with examples.
2. Discuss the int(), float(), str(), chr() and complex() type conversion functions with
examples.
3. Discuss the ord(), hex(), oct(), complex() and float() type conversion functions with
examples.
4. Describe the is and is not operators and type() function. Also, discuss why Python is called
as dynamic and strongly typed language.
5. What is Python? Describe its features and applications?
6. Differentiate between lists and tuples in Python?
7. Explain in detail about Python type conversion and type casting?
8. What are operators in Python? Describe specifically about identity membership operator?
UNIT:2 (10 Hours)
Python Program Flow Control : Conditional blocks using if, else and elif, Simple for loops in
python, For loop using ranges, string, list and dictionaries, Use of while loops in python, Loop
manipulation using pass, continue, break and else, Programming using Python conditional and
loops block
Python Functions, Modules And Packages: Organizing python codes using functions,
Organizing python projects into modules, Importing own module as well as external modules,
Understanding Packages, Powerful Lamda function in python, Programming using functions,
modules and external packages
Python String, List And Dictionary Manipulations : Building blocks of python programs,
Understanding string in build methods, List manipulation using in build methods, Dictionary
manipulation, Programming using string, list and dictionary in build functions
Multi Choice Question of UNIT II:
1. What will be the output of the following Python code snippet?
k = [print(i) for i in my_string if i not in "aeiou"]
a) prints all the vowels in my_string
b) prints all the consonants in my_string
c) prints all characters of my_string that aren’t vowels
d) prints only on executing print(k)
2. What will be the output of the following Python code snippet?
x = [i**+1 for i in range(3)]; print(x);
a) [0, 1, 2] b) [1, 2, 5]
c) error, **+ is not a valid operator d) error, ‘;’ is not allowed
3. What will be the output of the following Python code snippet?
print([[i+j for i in "abc"] for j in "def"])
a) [‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]
b) [[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
c) [[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
d) [‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]
4. What will be the output of the following Python code?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
a) [‘ab’, ‘cd’] b) [‘AB’, ‘CD’]
c) [None, None] d) none of the mentioned
5. What will be the output of the following Python code?
i=1
while True:
if i%2 == 0:
break
print(i)
i += 2
a) 1 b) 1 2
c) 1 2 3 4 5 6 … d) 1 3 5 7 9 11 …
6. What will be the output of the following Python code?
True = False
while True:
print(True)
break
a) True b) False
c) None d) none of the mentioned
7. What will be the output of the following Python code?
x = "abcdef"
while i in x:
print(i, end=" ")
a) a b c d e f b) abcdef
c) i i i i i i … d) error
8. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
print(i, end = " ")
a) i i i i i I b) a a a a a a
c) a a a a a d) none of the mentioned
9. What will be the output of the following Python code?
for i in range(2.0):
print(i)
a) 0.0 1.0 b) 0 1
c) error d) none of the mentioned
10. What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]:
print (i)
a) 1 2 3 4 b) 4 3 2 1
c) error d) none of the mentioned
11. What will be the output of the following Python code snippet?
for i in ''.join(reversed(list('abcd'))):
print (i)
a) a b c d
b) d c b a
c) error
d) none of the mentioned
12. What will be the output of the following Python code?
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
a) 0 1 2 3 4 Here b) 0 1 2 3 4 5 Here
c) 0 1 2 3 4 d) 1 2 3 4 5
13. What will be the output of the following Python code?
x = (i for i in range(3))
for i in x:
print(i)
for i in x:
print(i)
a) 0 1 2 b) error
c) 0 1 2 0 1 2 d) none of the mentioned
14. What will be the output of the following Python code snippet?
a = [0, 1, 2, 3]
for a[-1] in a:
print(a[-1])
a) 0 1 2 3 b) 0 1 2 2
c) 3 3 3 3 d) error
15. What will be the output of the following Python statement?
>>>"abcd"[2:]
a) a b) ab
c) cd d) dc
16. print(0xA + 0xB + 0xC):
a) 0xA0xB0xC b) Error
c) 0x22 d) 33
17. What will be the output of the following Python code?
>>>max("what are you")
a) error b) u
c) t d) y
18. Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).
a) __345.355 (2_ s) b) ___345.355 (3_s)
c) ____345.355 (4_s) d) _____345.354 (5_s)
19. What will be the output of the following Python code?
print('*', "abcdef".center(7), '*')
a) * abcdef * b) * abcdef *
c) *abcdef * d) * abcdef*
20. What will be the output of the following Python code?
print("abcdef".center(9, '1'))
a) 11abcdef1 b) 1abcdef11
c) 1abcdef1 d) error
21. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 2))
a) 2 b) 0
c) 1 d) none of the mentioned
22. What will be the output of the following Python code?
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(incr, elements)))
a) [1, 2, 3] b) [0, 1, 2]
c) error d) none of the mentioned
23. What will be the output of the following Python code?
x = ['ab', 'cd']
print(list(map(len, x)))
a) [‘ab’, ‘cd’] b) [2, 2]
c) [‘2’, ‘2’] d) none of the mentioned
24. In _______________ copy, the base address of the objects are copied. In _______________
copy, the base address of the objects are not copied.
a) deep. Shallow b) memberwise, shallow
c) shallow, deep d) deep, memberwise
25. What will be the output of the following Python code?
a = [1, 2, 3, 4, 5]
b = lambda x: (b (x[1:]) + x[:1] if x else [])
print(b (a))
a) 1 2 3 4 5 b) [5,4,3,2,1]
c) [] d) Error, lambda functions can’t be called recursively
Short Type Questions of UNITS II:
1. What are functions in Python?
2. What is __init__?
3. What is a lambda function?
4. What is self in Python?
5. How does break, continue and pass work?
6. What does [::-1} do?
7. How can you randomize the items of a list in place in Python?
8. What are python iterators?
9. How do you write comments in python?
10. What is pickling and unpickling?
11. What are docstrings in Python?
12. What is the purpose of is, not and in operators?
13. What is the usage of help() and dir() function in Python?
14. What is a dictionary in Python?
15. How can the ternary operators be used in python?
16. What does this mean: *args, **kwargs? And why would we use it?
17. What does len() do?
18. What are negative indexes and why are they used?
19. How to import modules in python?
20. What are Python libraries? Name a few of them.
21. What is module and package in Python?
22. How can you share global variables across modules?
Long Type Questions of Unit II:
1. Illustrate the different types of control flow statements available in Python with flowcharts.
2. Write a Program to Prompt for a Score between 0.0 and 1.0. If the Score is out of range,
print an error. If the score is between 0.0 and 1.0, print a grade using the following table
3. Write a program to display the fibonacci sequences up to nth term where n is provided by
the user.
4. Write a program to repeatedly check for the largest number until the user enters “done”.
5. Write a program to find the sum of all Odd and Even numbers up to a number specified by
the user.
6. Explain the need for continue and break statements. Write a program to check whether a
number is prime or not. Prompt the user for input.
7. Describe the syntax for the following functions and explain with an example.
a) abs() b) max() c) divmod() d) pow() e) len()
8. Write Pythonic code to solve the quadratic equation ax**2 + bx + c = 0 by getting input for
coefficients from the user.
9. Find the area and perimeter of a circle using functions. Prompt the user for input.
10. Write a Python program using functions to find the value of nPr and nCr without using
inbuilt factorial() function.
11. Write a program to print the sum of the following series 1 + 1/2 + 1/3 +. …. + 1/n
12. Write a function which receives a variable number of strings as arguments. Find unique
characters in each string.
13. Check if the items in the list are sorted in ascending or descending order and print suitable
messages accordingly. Otherwise, print “Items in list are not sorted”
14. Write Pythonic code to multiply two matrices using nested loops and also perform transpose
of the resultant matrix.
15. Write Python program to sort words in a sentence in decreasing order of their length.
Display the sorted words along with their length
16. Write Pythonic code to create a function called most_frequent that takes a string and prints
the letters in decreasing order of frequency. Use dictionaries.