Wednesday, February 19, 2020

Python Quiz

1.What is output for − 'search'. find('S') ?
s -1 ‘ ‘ None of the above

2.What is the output of following code −[ (a,b) for a in range(3) for b in range(a) ]
[ (1,0),(2,1),(3,2)] [ (0,0),(1,1),(2,2)] [(1,0),(2,1),(2,1)] [ (1,0),(2,0),(2,1)]

3.How can we generate random numbers in python using methods?
random.uniform () random.randint() random.random() All of the above

4.Suppose we have a set a = {10,9,8,7}, and we execute a.remove(14) what will happen ?
We cannot remove an element from set. Method is executed but no exception is raised. Key error is raised. There doesn’t exist such method as remove.

5.Which code is used to open a file for binary writing?
''w'' ''wb'' ''r+'' ''a''

No comments: