Correct Answer : Guido van Rossum
Correct Answer : 1991
Correct Answer : All of the above.
Correct Answer : #
Correct Answer : Objects are created from classes.
Correct Answer : Non-static
Correct Answer : def
Correct Answer : PYTHONHOME
Correct Answer : print
Correct Answer : re
Correct Answer : pass
Correct Answer : Variable name can start with an underscore.
Correct Answer : Python’s syntax is much like PHP
Correct Answer : int
if __name__ == "__main__": somemethod()
Correct Answer : Run python module as main program
Correct Answer : ==
Correct Answer : import math
Correct Answer : open(filename, mode)
Correct Answer : isnumeric()
Correct Answer : Integer division
Correct Answer : input()
Correct Answer : python do not have any data type for characters they are treated as string.
apple = mango​
Correct Answer : NameError
print type(1J)
Correct Answer : <type 'complex'>
import re sentence = 'Learn Python Programming' test = re.match(r'(.*) (.*?) (.*)', sentence) print(test.group())
Correct Answer : Learn Python Programming
Correct Answer : 3
Correct Answer : sampleTuple = (1,2,3,4,5)
Correct Answer : print(a[:100]) => [1,2,3,4,5]
print(1, 2, 3, 4, sep='*')​
Correct Answer : 1*2*3*4
numbers = [2, 3, 4] print(numbers)
Correct Answer : [2, 3, 4]
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']​
Correct Answer : yellow
print(3 >= 3)​
Correct Answer : True
print(type([1,2]))​
Correct Answer : <class 'list'>
>>> str1 = 'hello' >>> str2 = ',' >>> str3 = 'world' >>> str1[-1:]​
Correct Answer : o
>>>str1="helloworld" >>>str1[::-1]
Correct Answer : dlrowolleh
def f(a, b): print(a, b) f(b=1, *(2,))​
Correct Answer : 2 1
Correct Answer : To give a class the methods and variables of an interface
a = [1,2,3] a[-3:-1] = 10,20,30,40
Correct Answer : [10, 20, 30, 40, 3]
def f(a,b): return a,b f(**{'b':2,'a':1})​
Correct Answer : (1, 2)
Correct Answer : decimal
Correct Answer : iter loop
Correct Answer : a loop called from an object
Correct Answer : while a < 10:
Correct Answer : print l->get(0)
nums = set([1,1,2,3,3,3,4]) print(len(nums))​
Correct Answer : 4
Correct Answer : a = 2
Correct Answer : X=
Correct Answer : if a >= 22:
import time time.asctime()
Correct Answer : Current date and time
Correct Answer : def someFunction():
Correct Answer : re.purge()
Correct Answer : myExample = {‘someItem’: 2, ‘otherItem’: 20}
Correct Answer : f = open(“test.txt”, “r”)
Correct Answer : >>> re.match(‘ab*’, ‘ba’)
import turtle t=turtle.Pen t.tilt(75) t.forward(100)​
Correct Answer : A straight line of 100 units lying along the horizontal
str = "freetime" print (str[1:3])
Correct Answer : yes
Correct Answer : Class
Explanation : Class is a user defined data type.
Correct Answer : none of the mentioned
Explanation : All the statements will execute successfully but at the cost of reduced readability.
Correct Answer : //
Correct Answer : False
Correct Answer : k = 2 + 3l
Correct Answer : 1
Correct Answer : Float
Correct Answer : Left to Right
Correct Answer : -5
Explanation : First this expression will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
Correct Answer : +5
Explanation : ~x is equivalent to -(x+1)
Correct Answer : Parentheses
Correct Answer : float(’12+34′)
Explanation : ‘+’ cannot be converted to a float.
Correct Answer : ()
Correct Answer : 13
Correct Answer : Id returns the identity of the object
4 + 3 % 5
Correct Answer : 7
Correct Answer : **
x = int(43.55+2/2)
Correct Answer : 44
2**(3**2) (2**3)**2 2**3**2
Correct Answer : 512, 64, 512
8/4/2, 8/(4/2)
Correct Answer : (1.0, 4.0)
X=”hi” print(“05d”%X)
Correct Answer : error
Correct Answer : print(“%-ns”%S)
l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(l)
Correct Answer : ‘first=H, third=L’
l=list('HELLO') p=l[0], l[-1], l[1:3] 'a={0}, b={1}, c={2}'.format(*p)
Correct Answer : “a=H, b=O, c=[‘E’, ‘L’]”
hex(255), int('FF', 16), 0xFF
Correct Answer : (‘0xff’, 255, 255)
'{a}{b}{a}'.format(a='hello', b='world')
Correct Answer : ‘helloworldhello’
'The {} side {1} {2}'.format('bright', 'of', 'life')
Correct Answer : Error
i. '{0}'.format(4.56) ii. '{0}'.format([4.56,])
Correct Answer : ‘4.56’, ‘[4.56]’
Correct Answer : ‘There are %d %s birds.’ %(4, blue)
x=3.3456789 '%f | %e | %g' %(x, x, x)
Correct Answer : ‘3.345679 | 3.345679e+00 | 3.34568’
a='hello' q=10 vars()
Correct Answer : {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}
'%x %d' %(255, 255)
Correct Answer : ‘ff, 255’
>>>"a"+"bc"
Correct Answer : abc
class father: def __init__(self, param): self.o1 = param class child(father): def __init__(self, param): self.o2 = param >>>obj = child(22) >>>print "%d %d" % (obj.o1, obj.o2)
Correct Answer : Error is generated
>>>example = "snow world" >>>print("%s" % example[4:7])
Correct Answer : wo
>>>example = "helle" >>>example.find("e")
>>>example="helloworld" >>>example[::-1].startswith("d")
Correct Answer : s3 = s1.__add__(s2)
Correct Answer : s.__getitem__(3)
Correct Answer : s1.__contains__(s2)
class Count: def __init__(self, count = 0): self.__count = count c1 = Count(2) c2 = Count(2) print(id(c1) == id(c2), end = " ") s1 = "Good" s2 = "Good" print(id(s1) == id(s2))
Correct Answer : False True
Correct Answer : input(“Enter a string”)
print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))
Correct Answer : Hello foo and bin
print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))
print('{:,}'.format(1112223334))
Correct Answer : 1,112,223,334
print('{0:.2%}'.format(1/3))
Correct Answer : 33.33%
print('a B'.isalpha())
print('my_string'.isidentifier())
print('cd'.partition('cd'))
Correct Answer : (”, ‘cd’, ”)
print('abcdef12'.replace('cd', '12'))
Correct Answer : ab12ef12
print('abcdefcdghcd'.split('cd'))
Correct Answer : [‘ab’, ‘ef’, ‘gh’, ”]
Correct Answer : all of the mentioned
Correct Answer : 12454
Correct Answer : random.shuffle(list1)
Correct Answer : [2, 33, 222, 14]
Correct Answer : [0.0, 0.5, 1.0, 1.5]
>>>list1 = [11, 2, 23] >>>list2 = [11, 2, 2] >>>list1 < list2 is
Correct Answer : list1.remove(“hello”)
Correct Answer : 2
Correct Answer : [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
>>>"Welcome to Python".split()
Correct Answer : [“Welcome”, “to”, “Python”]
myList = [1, 5, 5, 5, 5, 1] max = myList[0] indexOfMax = 0 for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i >>>print(indexOfMax)
myList = [1, 2, 3, 4, 5, 6] for i in range(1, 6): myList[i - 1] = myList[i] for i in range(0, 6): print(myList[i], end = " ")
Correct Answer : 2 3 4 5 6 6
def f(values): values[0] = 44 v = [1, 2, 3] f(v) print(v)
Correct Answer : [44, 2, 3]
>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]
Correct Answer : [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
values = [[3, 4, 5, 1], [33, 6, 1, 2]] v = values[0][0] for row in range(0, len(values)): for column in range(0, len(values[row])): if v < values[row][column]: v = values[row][column] print(v)
Correct Answer : 33
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]] for row in values: row.sort() for element in row: print(element, end = " ") print()
Correct Answer : The program prints two rows 1 3 4 5 followed by 1 2 6 33
def m(list): v = list[0] for e in list: if v < e: v = e return v values = [[3, 4, 5, 1], [33, 6, 1, 2]] for row in values: print(m(row), end = " ")
Correct Answer : 5 33
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] def ttt(m): v = m[0][0] for row in m: for element in row: if v < element: v = element return v print(ttt(data[0]))
k = [print(i) for i in my_string if i not in "aeiou"]
Correct Answer : prints all characters of my_string that aren’t vowels
my_string = "hello world" k = [(i.upper(), len(i)) for i in my_string] print(k)
Correct Answer : [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
x = [i**+1 for i in range(3)]; print(x);
Correct Answer : [0, 1, 2]
print([i.lower() for i in "HELLO"])
Correct Answer : [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
print([[i+j for i in "abc"] for j in "def"])
Correct Answer : [[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
Correct Answer : [1/x for x in (1, 2, 3)]
w="hello" v=('a', 'e', 'i', 'o', 'u')
Correct Answer : [x for x in w if x in v]
t=32.00 [round((x-32)*5/9) for x in t]
Correct Answer : [x for x in range(1000) if x%3==0]
for i in range(1, 101): if int(i*0.5)==i*0.5: print(i)
Correct Answer : [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
Correct Answer : [(2**x) for x in range(0, 13)]
l=["good", "oh!", "excellent!", "#450"] [n for n in l if n.isalpha() or n.isdigit()]
Correct Answer : [‘good’]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] A[1]
Correct Answer : [4, 5, 6]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [A[row][1] for row in (0, 1, 2)]
Correct Answer : [2, 5, 8]
l=[[1, 2, 3], [4, 5, 6]] for i in range(len(l)): for j in range(len(l[i])): l[i][j]+=10 l
Correct Answer : [[11, 12, 13], [14, 15, 16]]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] [[col + 10 for col in row] for row in A]
Correct Answer : [[11, 12, 13], [14, 15, 16], [17, 18, 19]]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] B = [[3, 3, 3], [4, 4, 4], [5, 5, 5]] [[col1 * col2 for (col1, col2) in zip(row1, row2)] for (row1, row2) in zip(A, B)]
Correct Answer : [[3, 6, 9], [16, 20, 24], [35, 40, 45]]
Correct Answer : t[3] = 45
>>>t=(1,2,4,3) >>>t[1:3]
Correct Answer : (2, 4)
>>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)]
Correct Answer : [1, 4, 8]
numberGames = {} numberGames[(1,2,4)] = 8 numberGames[(4,2,1)] = 10 numberGames[(1,2)] = 12 sum = 0 for k in numberGames: sum += numberGames[k] print len(numberGames) + sum
>>> a,b=1,2,3
Correct Answer : No, too many values to unpack
>>> a,b=6,7 >>> a,b=b,a >>> a,b
Correct Answer : (7,6)
>>> a=2,3,4,5 >>> a
Correct Answer : Yes, (2,3,4,5) is printed
>>> a=(1,2,3) >>> b=a.update(4,)
Correct Answer : No because tuples are immutable
Correct Answer : set([[1,2],[3,4]])
a = [5,5,6,7,7,7] b = set(a) def test(lst): if lst in b: return 1 else: return 0 for i in filter(test, a): print(i,end=" ")
Correct Answer : 5 5 6 7 7 7
>>> a={5,4} >>> b={1,2,4,5} >>> a<b
>>> a={4,5,6} >>> b={2,8,6} >>> a-b
Correct Answer : {4,5}
>>> a={3,4,5} >>> b={5,6,7} >>> a|b
Correct Answer : {3, 4, 5, 6, 7}
s=set() type(s)
<class ‘set’>
<’set’>
Correct Answer : <class ‘set’>
Correct Answer : s={san}
l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
Correct Answer : [x**3 for x in l]
s1={3, 4} s2={1, 2} s3=set() i=0 j=0 for i in s1: for j in s2: s3.add((i,j)) i+=1 j+=1 print(s3)
Correct Answer : {(4, 2), (3, 1), (4, 1), (5, 2)}
Correct Answer : pop
Correct Answer : s2.issuperset(s1)
>>> a={1:"A",2:"B",3:"C"} >>> del a
Correct Answer : del deletes the entire dictionary
total={} def insert(items): if items in total: total[items] += 1 else: total[items] = 1 insert('Apple') insert('Ball') insert('Apple') print (len(total))
numbers = {} letters = {} comb = {} numbers[1] = 56 numbers[3] = 7 letters[4] = 'B' comb['Numbers'] = numbers comb['Letters'] = letters print(comb)
Correct Answer : {‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}
test = {1:'A', 2:'B', 3:'C'} del test[1] test[1] = 'D' del test[2] print(len(test))
a={} a['a']=1 a['b']=[2,3,4] print(a)
Correct Answer : {‘b’: [2, 3, 4], ‘a’: 1}
>>>import collections >>> b=collections.Counter([2,2,3,4,4,4]) >>> b.most_common(1)
Correct Answer : [(4, 3)]
>>> import collections >>> a=collections.Counter([2,2,3,3,3,4]) >>> b=collections.Counter([2,2,3,4,4]) >>> a|b
Correct Answer : Counter({3: 3, 2: 2, 4: 2})
Correct Answer : (x**y) % z
any([2>8, 4>2, 1>2])
4>2
min(max(False,-3,-4), 2,7)
Correct Answer : list(reversed(l))
Correct Answer : ord(‘ ‘)
def printMax(a, b): if a > b: print(a, 'is maximum') elif a == b: print(a, 'is equal to', b) else: print(b, 'is maximum') printMax(3, 4)
Correct Answer : 4 is maximum
def maximum(x, y): if x > y: return x elif x == y: return 'The numbers are equal' else: return y print(maximum(2, 3))
Correct Answer : All of the mentioned
def cube(x): return x * x * x x = cube(3) print x
Correct Answer : 27
Correct Answer : A local variable
i=0 def change(i): i=i+1 return i change(1) print(i)
Correct Answer : 0
def a(b): b = b + [5] c = [1, 2, 3, 4] a(c) print(len(c))
Correct Answer : 5
def display(b, n): while n > 0: print(b,end="") n=n-1 display('z',3)
Correct Answer : zzz
Correct Answer : number of arguments + 1
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
Correct Answer : [1]
def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])
Correct Answer : 3 1
def foo(x): x = ['def', 'abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
def foo(i, x=[]): x.append(i) return x for i in range(3): print(foo(i))
Correct Answer : [0] [0, 1] [0, 1, 2]
def f1(): x=15 print(x) x=12 f1()
Correct Answer : 15
def san(x): print(x+1) x=-2 x=4 san(12)
x=12 def f1(a,b=x): print(a,b) x=15 f1(4)
Correct Answer : 4 12
def fact(num): if num == 0: return 1 else: return ________
Correct Answer : num*fact(num-1)
def test(i,j): if(i==0): return j else: return test(i-1,i+j) print(test(4,7))
Correct Answer : 17
l=[] def convert(b): if(b==0): return l dig=b%2 l.append(dig) convert(b//2) convert(6) l.reverse() for i in l: print(i,end="")
Correct Answer : 110
def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))
Correct Answer : 100
def check(n): if n < 2: return n % 2 == 0 return check(n - 2) print(check(11))
def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2) for i in range(0,4): print(a(i),end=" ")
Correct Answer : 0 1 1 2
a = [1, 2, 3, 4, 5] b = lambda x: (b (x[1:]) + x[:1] if x else []) print(b (a))
Correct Answer : [ ]
odd=lambda x: bool(x%2) numbers=[n for n in range(10)] print(numbers) n=list() for i in numbers: if odd(i): continue else: break
Correct Answer : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
import functools l=[1,2,3,4] print(functools.reduce(lambda x,y:x*y,l))
Correct Answer : 24
l=[1, -2, -3, 4, 5] def f1(x): return x<-1 m1=map(f1, l) print(list(m1))
Correct Answer : [False, True, True, False, False]
import functools l=[1, 2, 3, 4, 5] m=functools.reduce(lambda x, y:x if x>y else y, l) print(m)
m=reduce(lambda x: x-3 in range(4, 10)) print(list(m))
Correct Answer : No output
elements = [0, 1, 2] def incr(x): return x+1 print(list(map(incr, elements)))
Correct Answer : [1, 2, 3]
def to_upper(k): return k.upper() x = ['ab', 'cd'] print(list(map(upper, x)))
x = ['ab', 'cd'] print(map(len, x))
Correct Answer : None of the above
x = ['ab', 'cd'] print(len(list(map(list, x))))
x = [[0], [1]] print((' '.join(list(map(str, x))),))
Correct Answer : (‘[0] [1]’,)
x = [34, 56] print((''.join(list(map(str, x)))),)
Correct Answer : 3456
x = 'abcd' print(list(map(list, x)))
Correct Answer : [[‘a’], [‘b’], [‘c’], [‘d’]]
Correct Answer : Python code is both compiled and interpreted
Correct Answer : Each import package need not introduce a namespace
Correct Answer : Provides a means of reducing the size of the program
Correct Answer : Docstring
Correct Answer : The overall design of the program is addressed before the details
from math import factorial print(math.factorial(5))
Correct Answer : Error, the statement should be: print(factorial(5))
Correct Answer : -3.0
import datetime d=datetime.date(2016,7,24) print(d)
Correct Answer : 2017-07-24
tday=datetime.date.today() print(tday.month())
Correct Answer : 8
tday=datetime.date.today() bday=datetime.date(2017,9,18) t_day=bday-tday
Correct Answer : print(t_day.months)
Correct Answer : import random
import random random.choice(2,3,4)
random.choice('sun')
Correct Answer : either s, u or n
random.seed(3) random.randint(1,5) 2 random.seed(3) random.randint(1,5)
random.randrange(1,100,10)
Correct Answer : 91
Correct Answer : sys.version
import sys if sys.platform[:2]== 'wi': print("Hello")
Correct Answer : Hello
import sys eval(sys.stdin.readline()) "India"
Correct Answer : ‘India’
import sys sys.stderr.write(“hello”)
Correct Answer : hello5
Correct Answer : print(dir(sys))
Correct Answer : the user id of the current process
Correct Answer : os.mkdir()
import turtle t=turtle.Pen() for i in range(0,4): t.forward(100) t.left(120)
Correct Answer : triangle
import turtle t=turtle.Pen() for i in range(0,3): t.forward(150) t.right(_____)
Correct Answer : 120
import turtle t=turtle.Pen() t.goto(300,9) t.position()
Correct Answer : 300.00, 9.00
import turtle t=turtle.Pen() for i in range(0,3): t.forward(100) t.left(120) t.back(100) for i in range(0,3): t.forward(100) t.left(120)