0% found this document useful (0 votes)
3 views13 pages

Python Question-bank[1] (1)

The document is a question bank for Python programming, covering various topics such as features, applications, and operators of Python. It includes questions on input and print commands, variable types, loops, and control statements, along with examples and explanations. Additionally, it differentiates between data types like lists, tuples, and sets, and discusses numeric and sequence types in Python.

Uploaded by

abc674657
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)
3 views13 pages

Python Question-bank[1] (1)

The document is a question bank for Python programming, covering various topics such as features, applications, and operators of Python. It includes questions on input and print commands, variable types, loops, and control statements, along with examples and explanations. Additionally, it differentiates between data types like lists, tuples, and sets, and discusses numeric and sequence types in Python.

Uploaded by

abc674657
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/ 13

dQuestion Bank

Python Programming ( BTETOE605E)

1. State and explain any six features of python.


2. State any six applications of python.
Ans. : 1. Web development -- Python can be used to make web-
applications at a rapid rate. This is because Python comes up with a wide
range of frameworks like Django, Flask, Bottle, and a lot more that provide
ease to developers.
2.Game development -- With the rapidly growing gaming
industry Python has proved to be an exceptional option for game
development. Popular games like Pirates of the Caribbean, Bridge
commander, and Battlefield 2 use Python programming for a wide range of
functionalities and addons. The presence of popular 2D and 3D gaming
libraries like pygame, panda3D, and Cocos2D make the game development
process completely effortless.
3.machine learning and artificial intelligence -- Machine
Learning and Artificial Intelligence are the hottest subjects right now.
Python along with its inbuilt libraries and tools facilitate the development of
AI and ML algorithms. Further, it offers simple, concise, and readable code
which makes it easier for developers to write complex.
4.Data science and data visualization -- Data science involves data
collection, data sorting, data analysis, and data visualization.
5.Desktop GUI -- Python is an interactive programming language that
helps developers to create GUIs easily and efficiently. It has a huge list of
inbuilt tools like PyQT, kivy, wxWidgets, and many other libraries like them
to build a fully functional GUI in an extremely secure and efficient manner.
6.Web scraping applications -- Web scraping is an automated process
used to extract information from websites in an easier and faster way. The
information is used by researchers, organizations, and analysts for a wide
variety of tasks.
3. State any six reasons, why you must consider writing software applications
in Python.
Ans. : 1. code is easy to read, use and maintain
2. compatible with major platform and system
3. large standard libraires

Page 1 of 13
4. cost effective approach
5. support multiple programming paradigms
6. adopt test driven development
4. Explain input command in python with suitable example.
Ans. : In Python, we use input() function to take input from the user.
Whatever you enter as input, the input function converts it into a string. If
you enter an integer value still input() function convert it into a string.
Syntax: input(prompt)
Ex. String= input()
Print (String)
5. Explain print command in python with suitable example.
Ans. : print() function prints the message to the screen or any other
standard output device.
Syntax: print(value(s), sep= ‘ ‘, end = ‘\n’, file=file, flush=flush)
Ex. : print(“Hello”)
6. State which of the following python statements are valid and invalid.
a. print("ksk", + "123") invalid
b. print("ksk" '+' "123") valid
c. print("ksk", '+', "123") valid
d. print('ABC is a "technological" University') valid
e. print(2 + '3') invalid
f. print('2' * 3) valid
7. What will be the output of following print statements?
a. print('abc' * 2) abcabc
b. print(3+4j + 2+1j) (5 + 5j)
c. print(3*2 // 4) 1
8. State which of the following python statements are valid and invalid.
a. x = input("enter a number") valid
b. x = input() valid
c. x = input("") valid
d. x = input(" ' ") invalid
e. x = input(2) valid
f. x=input("2" + "3") valid

Page 2 of 13
9. What will be the value of variables x, y & z after execution of following
python program. Assume that user enters a value 5.
temp=input("enter a number")
x=temp*5
y=int(temp)*5
z=bool(temp*0)

Ans. X= 55555 y = 25 and z = false

10. What will be the output of following program? Assume that user will enter
only integer value.
temp=input("enter a
number") x=temp*0
y=int(temp)*0
z=bool(temp*0) print(x)
print(y) print(z)
Ans. X= 55555 y = 25 and z = false
if user enter 5 as integer
value

11. What are the types of following variables?


a. a = 55 int
b. b = ‘3 + 4j’ string
c. c = “1DBATU” string
d. d = 5 + 2j complex
e. e = a char
f. f = b+c

12. Rewrite following code with proper indentation to get the output as
Expected output Code without indentation

Page 3 of 13
cube of 1 is: abc = [1,2,3,4,5] for x
1 square of in abc: if x%2 == 0:
2 is: print("square of ", x ,
4 cube of "is:")
3 is: print(x**2)
27 square else:
of 4 is: print("cube of ", x , "is:")
16 cube print(x**3)
of 5 is:
125

Ans. : abc = [1,2,3,4,5]


for x in abc:
if x%2 == 0:
print("square of ", x , "is:")
print(x**2)
else:
print("cube of ", x , "is:")
print(x**3)
13. What will be the output of following print statements?
a. print(123,"\nabc")
b. print("****","\\n***","\\n**","\\n*")
c. print(" ' " ' " " ' " ' ")
Ans. : 123
abc
**** \n*** \n** \n*
‘ ““‘
14. Explain any six arithmetic operators of python with suitable examples of
each.
Ans. : 1. Addition :- + Ex. :- x+y
2. Subtraction :- - Ex. :- x-y
3. Multiplication:- * Ex. :- x*y
4. Division:- / Ex. :- x/y
5. Modulus :- % Ex. :- x%y

Page 4 of 13
6. Exponentiation:- ** Ex. :- x**y
7. Floor division:- // Ex. :- x//y
15. Explain any six assignment operators of python with suitable examples of
each.
Ans. : Assignment operators are used to assign the values to the variables.
1. Assign (=) : assign values of the right side of expression to the left
side operand. X = y+z
2. Add and Assign(+=) : this operand is used to add the right side
operand to the left side operand and store the result in the left side
operand. Ex. : X += Y
3. Subtract and Assign(-=)This operand is used to subtract right side
operand from the left side operand and store the result in the left
side operand. Ex. : X -= Y
4. Multiply and Assign(*=) this operand is used to multiply right side
operand with the left side operand and store the result in the left
side operand. Ex.: X *= Y
5. Divide and Assign(/=) : this operand is used to divide the left
operand to the right operand and then store the result in the left
operand. Ex. : X /= Y
6. Modulus and Assign (%=) : this operator is used to take the modulus
using the left and right operand and the store the result in the let
operand. Ex. : X %= Y
7. Divide(floor) and Assign(//=) : This operator is used to divide the
left operand with the right operand and then assigning the
result(floor) to the left operand. Ex. X //= Y
8. Exponent and Assign: This operator is used to calculate the
exponent(raise power) value using operands and then assigning
the result to the left operand. Ex. X **= Y
16. Explain all comparison operators of python with suitable examples of each.
Ans. : 1. Greater than: This operator returns True if the left operand is
greater than the right operand. Syntax: x > y
2. Less than : this operator returns true if the left operand is less
than the right operand , Syntax : X < Y
3. Equal to : this operator returns true if the left operand is equal to
the right operand . Syntax : X == Y
4. Not equal to : this operator return true if the left operand is not
equal to the right operand, Syntax : X != Y
Page 5 of 13
5. Greater than or equal to : this operator return true if the left
operand is greater than or equal to the right operand , Syntax : X >= Y
6. less than or equal to : this operator return true if the left operand
is less than or equal to the right operand , Syntax : X <= Y

17. Explain “and, or, not” operators of python with suitable examples of each.
Ans : AND – Logical AND true if both X and Y operands are true, Syntax: X and
Y.
EX. : a=5
b=6
c=1
if a > b and a > c:
print("a is greater")
elif b > a and b > c:
print("b is greater")
else:
print("c is greater")
OR – Logical OR true if either of the operand is true means any one of them
operand is true, Syntax : X or Y
Ex. :
NOT – Logical NOT true if operand is false, Syntax : not x

18. Explain following operators of python with suitable examples of each.


a. is b. in c. not in
ANS : 1. Is :- this is the identity operator used in python. It is used to
compare the objects, not if they are equal but if they are actually the same
object, with the same memory location. It returns true if both values are
same. Ex.- X is Y
2. in :- this is membership operator used in python. This operator is used
to check if the sequence is presented in object. It returns true if a
sequence with the specified value is present in the object. Ex. – X in Y
3. not in :- this is membership operator used in python. It returns true if a
sequence with the specified value is not present in object. Ex.- X not in Y
19. Explain all bitwise operators of python with suitable examples of each.

Page 6 of 13
ANS. : 1. & Bitwise AND operator : Operator copies a bit to the result if it exist
in both operands.
2. | Bitwise or operator: It copies a bit if it exists in either operand.
3. ~ Bitwise not operator: it returns 1’s complement of number.
4. ^ Bitwise xor operator: It copies the bit if it is set in one operand but
not both.
5. << (Binary Left Shift) : The left operand’s value is moved left by the
number of bits specified by the right operand.
6. >> (Binary Right Shift) : The left operand’s value is moved right by the
number of bits specified by the right operand.
EX. a = 0011 1100
b = 0000 1101
1. a & b = 12(0000 1100)
2. a | b = 61(0011 1101)
3. a ^ b = 49(0011 0001)
4. ~a = -61
5. a << 2 = 240(1111 0000)
6. a >> 2 = 15(0000 1111)

20. Explain while loop with suitable example?


Ans : Python While Loop is used to execute a block of statements repeatedly until
a given condition is satisfied. And when the condition becomes false, the line
immediately after the loop in the program is executed.
Syntax : while expression:
statement(s)
EX. : I = 1
While x <=10:
print(x)
I += 1

21. Explain for loop with suitable example?

Page 7 of 13
ANS : some times it is required to execute group of statements repeatedly
that time for loop is used.
Syntax : for variable in sequence :
Statement 1
Statement 2
EX : s= “orchid”
for x in s:
print(x)
o/p : o
r
c
h
i
d
22. Explain break, continue and pass statement with suitable example of each.
Ans : 1. Break statement :- The break statement is used to terminate the loop
or statement in which it is present. After that, the control will pass to the
statements that are present after the break statement, if available. If the break
statement is present in the nested loop, then it terminates only those loops which
contains break statement.
Syntax : break
EX.
2. continue statement:- Continue is also a loop control statement just like the
break statement. continue statement is opposite to that of break statement, instead of
terminating the loop, it forces to execute the next iteration of the loop.
As the name suggests the continue statement forces the loop to continue or execute
the next iteration. When the continue statement is executed in the loop, the code inside
the loop following the continue statement will be skipped and the next iteration of the
loop will begin.
Syntax : continue
EX.
3. Pass statement :- As the name suggests pass statement simply does nothing.
The pass statement in Python is used when a statement is required syntactically but you
do not want any command or code to execute. It is like null operation, as nothing will

Page 8 of 13
happen is it is executed. Pass statement can also be used for writing empty loops. Pass
is also used for empty control statement, function and classes.
Syntax : Pass
EX.

23. Differentiate between List, Tuple & Set with suitable examples of each.
Ans :

Page 9 of 13
24. Explain any three collection data types of Python with suitable examples of
each.
Ans : 1 . Numeric : In Python, numeric data type represent the data which has
numeric value. Numeric value can be integer, floating number or even complex
numbers. These values are defined as int, float and complex class in Python.
• Integers – This value is represented by int class. It contains positive or
negative whole numbers (without fraction or decimal). In Python there is no
limit to how long an integer value can be.
• Float – This value is represented by float class. It is a real number with floating
point representation. It is specified by a decimal point. Optionally, the
character e or E followed by a positive or negative integer may be appended
to specify scientific notation.
• Complex Numbers – Complex number is represented by complex class. It is
specified as (real part) + (imaginary part)j. For example – 2+3j
2. Sequence type : In Python, sequence is the ordered collection of similar or
different data types. Sequences allows to store multiple values in an organized and
efficient fashion. There are several sequence types in Python –
• String - A string is a collection of one or more characters put in a single quote,
double-quote or triple quote. In python there is no character data type, a
character is a string of length one. It is represented by str class.
• List - Lists are just like the arrays, declared in other languages which is a
ordered collection of data. It is very flexible as the items in a list do not need
to be of the same type.
• Tuple - tuple is also an ordered collection of Python objects. tuples cannot be
modified after it is created. It is represented by tuple class.
3. Boolean : Data type with one of the two built-in values, True or False. Boolean
objects that are equal to True are truthy (true), and those equal to False are falsy
(false). But non-Boolean objects can be evaluated in Boolean context as well and
determined to be true or false. It is denoted by the class bool.
3. Set : Set is an unordered collection of data type that is iterable, mutable and has
no duplicate elements. The order of elements in a set is undefined though it may
consist of various elements.
4. Dictionary : in Python is an unordered collection of data values, used to store data
values like a map, which unlike other Data Types that hold only single value as an
element, Dictionary holds key:value pair. Key-value is provided in the dictionary to
make it more optimized. Each key-value pair in a Dictionary is separated by a colon :,
whereas each key is separated by a ‘comma’.

Page 10 of 13
25. Explain append() and copy() methods of list with suitable examples of each.
Ans : 1. append() Used for appending and adding elements to List. It is used to
add elements to the last position of the List in Python.
Syntax: list.append (element)
EX. : List = ['Mathematics', 'chemistry', 1997, 2000]
List.append(20544)
print(List)
2. Copy() It returns a shallow copy of a list
Syntax : list.copy()
EX. : lis1 = [ 1, 2, 3, 4 ]
lis2 = lis1.copy()
print(lis2)

26. Explain count() and index() methods of list with suitable examples of each.
Ans : 1. The count() method is one of the inbuilt functions in Python. As the name implies, it
returns the number of times a specified value appears in a string or a list. This method is also
used to count numbers in the given set of arrays. There are two types of methods for ‘count’ in
Python. They are as follows:
1. String count() method
2.List count() method
EX : myText = "I love Paris, Paris is my favorite tourist destination"
numofCounts = myText.count("Paris")
2. Index() : Python index() is an inbuilt function in Python, which searches for a
given element from the start of the list and returns the index of the first
occurrence.
Syntax: list_name.index(element, start, end)
EX : list2 = ['cat', 'bat', 'mat', 'cat', 'pet']
print(list2.index('bat'))

27.Explain insert() and remove() methods of list with suitable examples of


each.
Ans : 1. insert() Function is a Python library function that is used to insert the given element at
a particular index in a list.
Syntax: list_name.insert(index, element)
EX : lis = ['Geeks', 'Geeks']

Page 11 of 13
lis.insert(1, "For")
print(lis)
2. Python List remove() is an inbuilt function in the Python programming
language that removes a given object from the List.
Syntax: list_name.remove(obj)
EX : list1 = [ 1, 2, 1, 1, 4, 5 ]
list1.remove(1)
print(list1)

28.Explain reverse() and remove() methods of list with suitable examples of


each.
Ans: 1. reverse() is an inbuilt method in the Python programming language that
reverses objects of the List in place.
Syntax: list_name.reverse()
EX : list1 = [1, 2, 3, 4, 1, 2, 6]
list1.reverse()
print(list1)
2. remove() is an inbuilt function in the Python programming language that removes
a given object from the List.
Syntax: list_name.remove(obj)
EX : list1 = [ 1, 2, 1, 1, 4, 5 ]
list1.remove(1)
print(list1)

29. Explain clear() and extend() methods of list with suitable examples of each.
Ans : 1. The clear() method removes all the elements from a list.
Syntax : list.clear()
EX : fruits = ['apple', 'banana', 'cherry', 'orange']
fruits.clear()
2. extend() method iterates over an iterable like string, list, tuple, etc., and adds
each element of the iterable to the end of the List, modifying the original list.
Syntax : list.extend(iterable)
EX : l = [1, 2, 3]

Page 12 of 13
l.extend([4, 5, 6])
print(l)
30. Explain pop() and sort() methods of list with suitable examples of each.
Ans : pop() is an inbuilt function in Python that removes and returns the last value
from the List or the given index value.
Syntax : list_name.pop(index)
EX : l = [1, 2, 3, 4]
print("Popped element:", l.pop())
print("List after pop():", l)
2. remove() :- This function is used to delete the first occurrence of number
mentioned in its arguments.
Syntax : list_name.remove(index)
EX : lis = [2, 1, 3, 5, 3, 8]
lis.remove(3)

31. What will be the output of following python statements?


a. print(23 // 5)
Ans : 4
b. print(2 << 2)
Ans : 8
c. print(2 >> 0)
Ans : 2
d. print(2 ^ 2)
Ans : 0
e. print(2 != 2)
Ans : False
f. print(2 < 0)

Ans : False

Page 13 of 13

You might also like