TCS PA Python MCQs
1. What gets printedfoo = {}
print type(foo)
<class ‘dict’>
2. Type of error in ‘st’+1
Type error
3. Python supports regular expressions
True
4. Like the else, the elif statement is optional.
True
5. What gets printed?
numberGames={}
numberGames[(1,2,3)]=8
numberGames[(4,2,1)]=10
numberGames[(1,2)]=12
sum=0
for k in numberGames:
sum+=numberGames[k]
print len(numberGames)+sum
33
6.The readlines() method returns
a list of lines
7. Suppose s is “\t\tWorld\n”, what is s.strip()?
World
8. Function can not have return statement
False
9. What is the difference between a class and an object in python?
Objects are created from class
10. Raw_input() returns
String
11. Output of following code
Si=’spamandeggs’
X=si.find(‘and’)
print(x)
print(si[0:1],si[5:7])
4(‘s’,’nd’)
12. Which method is used to delete an object created by initializing constructor.
Destructor
13. To read two characters from a file object in file, we use
infile.read(2)
14. What would the statement “print('%.2f'%123.444)”
123.44
15. What can you put before and after a section to make all of the lines a comment?
'''
16. What gets printed ?
nums=set([1,1,2,3,3,3,4])
print(len(nums))
4
17.Python programming can handle every error implicitly
True
18. Syntax error is also called as
parsing error
19. Str1=’hello’
Str2=’,’
Str3=’world’
Str1[-1:]
o
20. Str1=’helloworld’
Str1[::-1]
dlrowolleh
21. 2.0+2
4.0
22. E=’hello’ print E.find(‘e’)
1
23. What arithmetic operator can not be used with strings?
**,-
24. Foo={1:’1’,2:’2’,3:’3’}
Foo={}
Print len(Foo)
0
25. Print ‘new’’line’
newline
26. Python is not suited for fast and memory intensive tasks
ANS: True
27. Enthought or rather EPD
Integrated development environment for python
28. Which of the following are immutable built-in types of python
numbers,strings,tuples
29. The format function returns:
str
30. How much control statements python supports?
3
31. Print “abcd”[2:]
cd
32. def myfunc(x,y,z,a):
print x+y
nums=[1,2,3,4]
myfunc(*nums)
3
33. example="snow world"
print "%s"%example[4:7]
wo
34. print str(1)+str(2)
12
35. Use of sys.stdout.flush() is
get that text on the screen quickly.
36. names=['Amir','Barry','Chales','Dao']
print names[-1][-1]
o
37. Suppose i is 5 and j is 4, i + j is same as
i.__add__(j)
38. what will be the output of the below code snippet?
print({} is {})
1.True
2.no
3.yes
4.false
39. Sets={3,4,5,6}
sets.update([1,2,3])
print(sets)
what is the output from the above snippet?
1.{1,2,3,3,4,5,6}
2.{1,2,3,4,5,6}
3.{1,2,4,5,6}
4.{1,2,3,4,5}
40. variable 'a' is defined as
a='gOOd moRning'
Select the statement which will convert the 'a' from 'gOOd moRning' to 'Good Morning'?
1.a.upper()
2.a.string()
3.a.title()
4.a.lower()
41. Mylist=['a','a',b','b','b','c','c','d','e']
Mylist.index('b')What is the output of the above code?
1. 2
2.3
3.4
4.5
42. what is the output of the below code?
s='Welcome$to$python'
print(s.split('$'));
1.Welcometopython
2.Welcome to python
3.['Welcome','to','python']
4.'Welcome','to','python'
43. import math
print(math.floor(5.5))
what is the output from the above code?
1.5.5
2.6
3. 5
4.0
44.in the python the below statement represents X=a+5-b
1.alphabets
2.operands
3. None of these
4.Terms
45. in the below list
Numbers=[1,2,3,4]
Numbers.append([5,6,7,8])
print(len(Numbers))
What is the output from the above snippet?
1. 5
2.12
3.8
4.7
46. What is the output of below python code
a=('a','b','c','d','e','f','g','h')
x=slice(3,5)
print(a[x])
1.('d','f')
2. ('d','e')
3.('c','f')
4.('c','e')
47. What is the output of below code
math.sqrt(36)
1. 6 Period 0
2.5
3.6
4.7
48. What is the output of below python code?
s='TCS'
r_str=s[::-1]
print(r_str)
1.TC
2. SCT
3.TCS
4.CS
49. my_tuple=(1,,5,3,9)
my_tuple.append((8,6,7))
print(len(my_tuple))
what is the output from the above code?
1.An exception is thrown
2.1
3.2
4.5
Comments
Post a Comment