TCS Python questions & Answers |2018

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 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
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 infile, we use
ANS: infile.read(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 sys.stdout.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)

1 comment:

  1. i want to more and more contents this was helpful for me tq

    ReplyDelete