Problem Solving and Python Programming

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse.

Which of the following is false statement in python

How can we generate random numbers in python using methods?

How can we check whether the object is instance of class or not. Let us consider an object O which is instance of class B.

What is the output of the following code?









>>> a,b=6,7
>>> a,b=b,a
>>> a,b







What is the output of the code?


try: 
list
= 5*[0]+5*[10]
x
= list[9]
print(''Done!'')
except IndexError:
print(''Index out of Bond! '')
else:
print(''Nothing is wrong!'')
finally:
print(''Finally block!'')

Which options are correct to create an empty set in Python?

Which method is used to convert raw byte data to a string?

Using the pack manager, how you can you put the components in a container in the same row?

Which can be an Identifier among them in Python?

Is Python case sensitive when dealing with identifiers?
All keywords in Python are in
Which of the following is true for variable names in Python?
What is the order of precedence in python?
i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction

In python we do not specify types,it is directly interpreted by the compiler, so consider the following operation to be performed.











  1. >>>x = 13 ? 2










objective is to make sure x has a integer value, select all that apply (python 3.xx)

What is the output of the following code?









{a**2 for a in range(4)}







Which of the following expressions involves coercion when evaluated in Python?

What is the output of the following?









x = ['ab', 'cd']
for i in x:
i.upper()
print(x)







What is the output of the following?









x = ['ab', 'cd']
for i in x:
x.append(i.upper())
print(x)







What is the output of each of the functions shown below?








{x for x in 'abc'}
{x*3 for x in 'abc'}







What is the output of the following?









i = 1
while True:
if i%0O7 == 0:
break
print(i)
i += 1







What is the output of the following?









i = 5
while True:
if i%0O11 == 0:
break
print(i)
i += 1







The output of the line of code shown below is: class<’set’>. State whether this statement is true or false.









type({})







What is the output of the following?









i = 1
while True:
if i%2 == 0:
break
print(i)
i += 2







What is the output of the following?









i = 2
while True:
if i%3 == 0:
break
print(i)
i += 2







What is the output of the following?









i = 1
while False:
if i%2 == 0:
break
print(i)
i += 2







What is the output of the following?









True = False
while True:
print(True)
break







What is the output when following statement is executed ?











  1. >>>"a"+"bc"









What is the output when following statement is executed ?











  1. >>>"abcd"[2:]









The output of executing string.ascii_letters can also be achieved by:

What is the output when following code is executed ?











  1. >>> str1 = 'hello'



  2. >>> str2 = ','



  3. >>> str3 = 'world'



  4. >>> str1[-1:]









What arithmetic operators cannot be used with strings ?

What is the output when following code is executed ?












  1. >>>print r"\nhello"










The output is


What is the output when following statement is executed ?











  1. >>>print('new' 'line')









What is the output when following statement is executed ?
>>> print(‘x\97\x98’)

What is the output when following code is executed ?











  1. >>>str1="helloworld"



  2. >>>str1[::-1]









print(0xA + 0xB + 0xC) :

What is the output when following code is executed ?











  1. >>>names = ['Amir', 'Bear', 'Charlton', 'Daman']



  2. >>>print(names[-1][-1])









The output of the code shown below is:









a=[1, 4, 3, 5, 2]
b=[3, 1, 5, 2, 4]
a==b
set(a)==set(b)







Suppose list1 is [1, 3, 2], What is list1 * 2 ?
Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is :

What is the output when following code is executed ?











  1. >>>list1 = [11, 2, 23]



  2. >>>list2 = [11, 2, 2]



  3. >>>list1 < list2 is









To add a new element to a list we use which command ?
To insert 5 to the third position in list1, we use which command ?
To remove string “hello” from list1, we use which command ?
Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5) ?
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5) ?

Is the following piece of code valid?









>>> a,b,c=1,2,3
>>> a,b,c







What is the output of the following piece of code?









a = ('check',)
n = 2
for i in range(int(n)):
a = (a,)
print(a)







Is the following line of code valid?









>>> a,b=1,2,3







What is the output of the following piece of code when executed in Python shell?









>>> a=(1,2)
>>> b=(3,4)
>>> c=a+b
>>> c







What is the output of the code shown below?









l=[1, 2, 4, 5, 2, 'xy', 4]
set(l)
l







The following piece of code is invalid. True or False?









class demo(dict):
def __test__(self,key):
return []
a = demo()
a['test'] = 7
print(a)







What is the output of the following code?









a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])







What is the output of the following snippet of code?









>>> b={}
>>> all(b)







What is the output of the following piece of code when executed in Python shell?









>>> import collections
>>> b=dict()
>>> b=collections.defaultdict(lambda: 7)
>>> b[4]







The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid. State whether this statement is true or false.

What are the outcomes of the function shown below?









x=3
eval('x^2')







Python supports the creation of anonymous functions at runtime, using a construct called __________

What is the output of this program?











  1. y = 6



  2. z = lambda x: x * y



  3. print z(8)









What is the output of below program?











  1. def f(x, y, z): return x + y + z



  2. f(2, 30, 400)









What is the type of each element in sys.argv?
What is the length of sys.argv?

What is the output of the following code?









def foo():
total += 1
return total
total = 0
print(foo())







What is the output of the following code?









def foo(x):
x = ['def', 'abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))







Which of the following data structures is returned by the functions globals() and locals()?

What is the output of the code shown below?









x=1
def cg():
global x
x=x+1
cg()
x







______________ returns a dictionary of the module namespace.
________________ returns a dictionary of the current namespace.
On assigning a value to a variable inside a function, it automatically becomes a global variable. State whether true or false.
Recursion and iteration are the same programming approach. True or False?
Which is the most appropriate definition for recursion?
Which of these is false about recursion?
Which of these is not true about recursion
In _______________ copy, the base address of the objects are copied.
In _______________ copy, the base address of the objects are not copied.

Which type of copy is shown in this code?









l1=[[10, 20], [30, 40], [50, 60]]
ls=list(l1)
ls
[[10, 20], [30, 40], [50, 60]]







The nested list undergoes shallow copy even when the list as a whole undergoes deep copy. State whether this statement is true or false.

What is the output of the code shown below?









l1=[1, 2, 3, [4]]
l2=list(l1)
id(l1)==id(l2)







What is the output of the piece of code given below?









def check(n):
if n < 2:
return n % 2 == 0
return check(n - 2)
print(check(11))







Which of these definitions correctly describes a module?
Program code making use of a given module is called a ______ of the module
______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.
What is the order of namespaces in which Python looks for an identifier?
In file handling, what does this terms means “r, a”?
What is the use of “w” in file handling?
Is it possible to create a text file in python?

Which function is called when the following code is executed?









f = foo()
format(f)







Which of the following will print True?









a = foo(2)
b = foo(3)
print(a < b)







Which operator is overloaded by the __or__() function?
Which function overloads the // operator?
Which of the following is not a class method?
Which piece of code creates an empty class?
Special methods need to be explicitly called during object creation. True or False?

Is the following piece of code valid?









class B(object):
def first(self):
print("First method called")
def second():
print("Second method called")
ob = B()
B.first(ob)







What type of inheritance is illustrated in the following piece of code?









class A():
pass
class B(A):
pass
class C(B):
pass







What does single-level inheritance mean?
Method issubclass() checks if a class is a subclass of another class. True or False?

What is the output of the following piece of code when executed in the Python shell?









>>> class A:
pass
>>> class B(A):
pass
>>> obj=B()
>>> isinstance(obj,A)







Which of the following best describes polymorphism?
What is the biggest reason for the use of polymorphism?
A class in which one or more methods are only implemented to raise an exception is called an abstract class. True or False?
Overriding means changing behaviour of methods of derived class methods in the base class. Is the statement true or false?
Which of the following is the most suitable definition for encapsulation?
Which of these is not a fundamental features of OOP?

What is the output of the following code?









class fruits:
def __init__(self):
self.price = 100
self.__bags = 5
def display(self):
print(self.__bags)
obj=fruits()
obj.display()







Which of the following is false about protected class members?

The code shown below will result in an error if the input value is entered as -5. State whether this statement is true or false.









assert False, 'Spanish'







What is the output of the code shown below?









#generator
def f(x):
yield x+1
g=f(8)
print(next(g))







What is the output of the code shown below?









def f(x):
yield x+1
print("test")
yield x+2
g=f(9)







What is the output of the following code?









def a():
try:
f(x, 4)
finally:
print('after f')
print('after f?')
a()







This entry was posted in . Bookmark the permalink.

Leave a Reply