[Go to site: main page, start]

TCS Python MCQ Exam Questions

100% found this document useful (2 votes)
3K views53 pages
This document contains 51 multiple choice questions about Python. The questions cover topics like data types (dictionaries, strings, tuples), functions, control flow, exceptions, modules, me…

Uploaded by

KOTHYADA JOSHNA
  • Introduction
  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5
  • Question 6
  • Question 7
  • Question 8
  • Question 9
  • Question 10
  • Question 11
  • Question 12
  • Question 13
  • Question 14
  • Question 15
  • Question 16
  • Question 17
  • Question 18
  • Question 19
  • Question 20
  • Question 21
  • Question 22
  • Question 23
  • Question 24
  • Question 25
  • Question 26
  • Question 27
  • Question 28
  • Question 29

TCS ONLINE PROCTORED EXAM

PYTHON MCQ
COMMON QUESTIONS
1. What gets printed
foo = {}
print type(foo)
ANS: <class ‘dict’>
2. Type of error in ‘st’+1
ANS: Type error
3. Python supports regular expressions
ANS: True
4. Like the else, the elif statement is optional.
ANS: 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
ANS: 33
6. The readlines() method returns
ANS: a list of lines
7. Suppose s is “\t\tWorld\n”, what is [Link]()?
ANS: World
8. Function can not have return statement
ANS: False
9. What is the difference between a class and an
object in python?
ANS: Objects are created from class
10. Raw_input() returns
ANS: String
11. Output of following code
Si=’spamandeggs’
X=si.find(‘and’)
Print(x)
Print(si[0:1],si[5:7])
ANS: 4(‘s’,’nd’)
12. Which method is used to delete an object created by initializing
constructor.
ANS: Destructor
13. To read two characters from a file object in file, we use
ANS: infi[Link](2)
14. What would the statement “print('%.2f'%123.444)”
ANS: 123.44
15. What can you put before and after a section to make all of the
lines a comment?
ANS: '''
16. What gets printed ?
nums=set([1,1,2,3,3,3,4])
Print len(nums)
ANS: 4
17. Python programming can handle every error
implicitly
ANS: True
18. Syntax error is also called as
ANS: parsing error
19. Str1=’hello’
Str2=’,’
Str3=’world’
Str1[-1:]
ANS: o
20. Str1=’helloworld’
Str1[::-1]
ANS: dlrowolleh
21. 2.0+2
ANS: 4.0
22. E=’hello’ print E.find(‘e’)
ANS: 1
23. What arithmetic operator can not be used with strings?
ANS: **,-
24. Foo={1:’1’,2:’2’,3:’3’}
Foo={}
Print len(Foo)
ANS: 0
25. Print ‘new’’line’
ANS: newline
26. Python is not suited for fast and memory intensive tasks
ANS: True
27. Enthought or rather EPD
ANS: Integrated development environment for python
28. Which of the following are immutable built-in types of python
ANS: numbers,strings,tuples
29. The format function returns:
ANS: str
30. How much control statements python supports?
ANS: 3
31. Print “abcd”[2:]
ANS: cd
32. def myfunc(x,y,z,a):
print x+y
nums=[1,2,3,4]
myfunc(*nums)
ANS: 3
33. example="snow world"
print "%s"%example[4:7]
ANS: wo
34. print str(1)+str(2)
ANS: 12
35. IndentError is not python built-in exception
36. Use of [Link].flush() is
ANS: get that text on the screen quickly.
37. names=['Amir','Barry','Chales','Dao']
print names[-1][-1]
ANS:o
38. Suppose i is 5 and j is 4, i + j is same as
ANS: i.__add__(j)
[Link] will be the output of the below code snippet?
print({} is {})
[Link]
[Link]
[Link]
[Link]
Ans:4
[Link]={3,4,5,6}
[Link]([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}
Ans:2
[Link] 'a' is defined as
a='gOOd moRning'
Select the statement which will convert the 'a' from 'gOOd
moRning' to 'Good Morning'?
[Link]()
[Link]()
[Link]()
[Link]()
Ans:3
[Link] will be the output of the below code snippet?
a=5;
b=5;
c=a+b;
print(c==(a+b));
[Link]
[Link] Error
3.c=10
[Link]
Ans:4
[Link]=['a','a',b','b','b','c','c','d','e']
[Link]('b')What is the output of the above code?
1.2
2.3
3.4
4.5
Ans:1
[Link] is the output of the below code?
s='Welcome$to$python'
print([Link]('$'));
[Link]
[Link] to python
3.['Welcome','to','python']
4.'Welcome','to','python'
Ans:3
[Link] math
print(math.floor(5.5))
what is the output from the above code?
1.5.5
2.6
3.5
4.0
Ans:3
[Link] the python the below statement represents X=a+5-b
[Link]
[Link]
[Link] of these
[Link]
Ans:3
[Link] the below list
Numbers=[1,2,3,4]
[Link]([5,6,7,8])
print(len(Numbers))
What is the output from the above snippet?
1.5
2.12
3.8
4.7
Ans:1
[Link] 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')
Ans:2
[Link] is the output of below code
[Link](36)
1.6 Period 0
2.5
3.6
4.7
Ans:1
[Link] is the output of below python code?
s='TCS'
r_str=s[::-1]
print(r_str)
[Link]
[Link]
[Link]
[Link]
Ans:2
51.my_tuple=(1,,5,3,9)
my_tuple.append((8,6,7))
print(len(my_tuple))
what is the output from the above code?
[Link] exception is thrown
2.1
3.2
4.5
Ans:1
THANK YOU

TCS ONLINE PROCTORED EXAM
PYTHON MCQ
COMMON QUESTIONS
1. What gets printed
foo = {}
print type(foo)
ANS: <class ‘dict’>
2. Type of error in ‘st’+1
ANS: Type error
3. Python supports regular expressions
ANS: True
4. Like the else, the elif statement is optional.
ANS: 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 numb
6. The readlines() method returns
ANS: a list of lines
7. Suppose s is “\t\tWorld\n”, what is s.strip()?
ANS: World
8. Function can not have return statement
ANS: False
9. What is the difference between a class and an
object in python?
ANS: Objects are created from class

You might also like