Call
whatsapp
9447387064 | 9847003556
0471-2335855 | 8089080088 | 0471-2334855
9447387064 | 9847003556
0471-2335855 | 8089080088 | 0471-2334855
Cisco Training in Trivandrum, Trinity Technologies

No.1 Training Institute in Kerala

PYTHON QUESTIONS : PART 13

What is the output of the code shown below?

#generator

def f(x):

          yield x+1

g=f(8)

print(next(g))

8

9

7

Error

SHOW ANSWER

What is the output of the following code?

def a():

    try:

        f(x,4)

    finally:

        print('after f')

    print('after f?')

a()

error

after f?

after f

    error

after f 

SHOW ANSWER

Which of the following blocks will be executed whether an exception is thrown or not?

except

else

finally

assert 

SHOW ANSWER

What is the output of the following program:

y=8

z= lambda x:x*y

print z(6)

48

14

64

none of the above 

SHOW ANSWER

Which of the following statement is true?

You cannot create custom exceptions in Python

You can create a user-defined exception by deriving a class from Exception class

You can create a user-defined exception by deriving a class from Error class

None of the above. 

SHOW ANSWER

Which of the following is correct?

An exception is an error that occurs at the runtime.

A syntax error is also an exception.

An exception is used to exclude a block of code in Python.

All of the above.

SHOW ANSWER

What is the output of the following code?

number = 5.0

try:

          r= 10/number

          print(r)

except:

          print("Oops! Error occurred.")

Oops! Error occurred.

2.0

2.0 Oops! Error occurred.

None object

SHOW ANSWER

What does the following code do?

try:

          # code that can raise error

          pass

except (TypeError, Zero DivisionError):

          print("Two")

Prints Two if exception occurs (doesn't matter which exception).

Prints Two if exception doesn't occur.

Prints Two if TypeError or Zero DivisionError exception occurs.

Prints Two only if both TypeError and Zero Division Error exception occurs.

Prints Two only if both

SHOW ANSWER

What does os.name contain?

the name of the operating system dependent module imported

the address of the module os

error, it should've been os.name()

none of the mentioned

SHOW ANSWER

What does os.getlogin() return?

a name of the current user logged in

name of the superuser

gets a form to login as a different user

all of the above

SHOW ANSWER

Which of the following functions can be used to read data from a file using a file descriptor?

os.reader()

os.read()

os.quick_read()

os.scan()

SHOW ANSWER

Which of the following can be used to create a directory?

os.mkdir()

os.creat_dir()

os.create_dir()

os.make_dir()

SHOW ANSWER

Which of the following returns a string that represents the present working directory?

os.getcwd()

os.cwd()

os.getpwd()

os.pwd()

SHOW ANSWER
BACK | NEXT
TRINITY SOFTWARE SOLUTIONS,IInd floor, Radheyam Towers, Gandhari Amman Kovil Road, Pulimood, Trivandrum - 1
0471-2334855 | 2335855 | 9447387064 | 9847003556 info@trinitytechnology.in