Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. What will be the output of the following Python code? a={} a[2]=1 a[1]=[2,3,4] print(a[1][1]) a) [2,3,4] b) 3 c) 2 d) An exception is

1. What will be the output of the following Python code?

a={}

a[2]=1

a[1]=[2,3,4]

print(a[1][1])

a) [2,3,4]

b) 3

c) 2

d) An exception is thrown

2. Read the following Python code carefully and point out the global variables?

y, z = 1, 2

def f():

global x

x = y+z

a) x

b) y and z

c) x, y and z

d) Neither x, nor y, nor z

3. Which of the following is the use of function in python?

a) Functions are reusable pieces of programs

b) Functions don't provide better modularity for your application

c) you can't also create your own functions

d) All of the mentioned

4. Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)?

a) (?:...)

b) (?=...)

c) (?!...)

d) (?#...)

5. What will be the output of the following Python code?

lamb = lambda x: x ** 3

print(lamb(5))

a) 15

b) 555

c) 125

d) None of the mentioned

6. What will be the output of the following Python code?

l1=[1, 2, 3, [4]]

l2=list(l1)

id(l1)==id(l2)

a) True

b) False

c) Error

d) Address of l1

7. What will be the output of the following Python code?

def f(p, q, r):

global s

p = 10

q = 20

r = 30

s = 40

print(p,q,r,s)

p,q,r,s = 1,2,3,4

f(5,10,15)

a) 1 2 3 4

b) 5 10 15 4

c) 10 20 30 40

d) 5 10 15 40

8. Which is/are the basic I/O connections in file?

a) Standard Input

b) Standard Output

c) Standard Errors

d) All of the mentioned

9. Which of the statements about dictionary values if false?

a) More than one key can have the same value

b) The values of the dictionary can be accessed as dict[key]

c) Values of a dictionary must be unique

d) Values of a dictionary can be a mixture of letters and numbers

10. Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]?

a) Since "susan" is not a value in the set, Python raises a KeyError exception

b) It is executed fine and no exception is raised, and it returns None

c) Since "susan" is not a key in the set, Python raises a KeyError exception

d) Since "susan" is not a key in the set, Python raises a syntax error

11. Which one of the following is not attributes of file?

a) closed

b) softspace

c) rename

d) mode

12. What will be the output of the following Python code?

import random

random.choice(2,3,4)

a) An integer other than 2, 3 and 4

b) Either 2, 3 or 4

c) Error

d) 3 only

13. What will be the output of the following Python code?

pickle.HIGHEST_PROTOCOL

a) 4

b) 5

c) 3

d) 6

14. What will be the output of the following Python code snippet?

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

d1 > d2

a) True

b) False

c) Error

d) None

15. What will be the output of the following Python code?

import re

re.ASCII

a) 8

b) 32

c) 64

d) 256

16. What will be the output of the following Python code?

int('65.43')

a) ImportError

b) ValueError

c) TypeError

d) NameError

17. What is a variable defined inside a function referred to as?

a) A global variable

b) A volatile variable

c) A local variable

d) An automatic variable

18. What will be the output of the following Python code?

def maximum(x, y):

if x > y:

return x

elif x == y:

return 'The numbers are equal'

else:

return y

print(maximum(2, 3))

a) 2

b) 3

c) The numbers are equal

d) None of the mentioned

19. To read two characters from a file object infile, we use ________

a) infile.read(2)

b) infile.read()

c) infile.readline()

d) infile.readlines()

20. What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

"john" in d

a) True

b) False

c) None

d) Error

21. What happens if the base condition isn't defined in recursive programs?

a) Program gets into an infinite loop

b) Program runs once

c) Program runs n number of times where n is the argument given to the function

d) An exception is thrown

22. Which of the following is not a valid namespace?

a) Global namespace

b) Public namespace

c) Built-in namespace

d) Local namespace

23. The function pow(x,y,z) is evaluated as:

a) (x**y)**z

b) (x**y) / z

c) (x**y) % z

d) (x**y)*z

24. What will be the output of the following Python code?

g = (i for i in range(5))

type(g)

a) class <'loop'>

b) class <'iteration'>

c) class <'range'>

d) class <'generator'>

25. Overriding means changing behaviour of methods of derived class methods in the base class.

a) True

b) False

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

In human being the duration of cardiac cycle is........?

Answered: 1 week ago

Question

Name the three phases of cardiac cycle in the order form.....?

Answered: 1 week ago

Question

Define psychology and it's school of thoughts in short ?

Answered: 1 week ago

Question

What is the most effective way to stop a nose bleed ?

Answered: 1 week ago