Quiz: Python Part-1

To View Tricks: Login Required

Number of Questions: 37

Question: 26 -

Study the following statements:

>>> print(ord('h') - ord('z'))  

What will be the output of this statement?

Options:
  1. 17

  2. 18

  3. -17

  4. -18

  5. Answer:

    -18

    Solution:

    ASCII value of h is less than the z. Hence the output of this code is 104-122, which is equal to -18.


Question: 27 -

Study the following program:

class book:  

    def __init__(a, b):  

        a.o1 = b  

   

class child(book):  

    def __init__(a, b):  

        a.o2 = b  

   

obj = page(32)  

print "%d %d" % (obj.o1, obj.o2)  

Which of the following is the correct output of this program?

Options:
  1. 32 32

  2. Error

  3. 32 None

  4. 32

  5. Answer:

    Error

    Solution:

    Error is generated because self.o1 was never created.


Question: 28 -

Study the following statement:

 
>>>"a"+"bc"  

What will be the output of this statement?

Options:
  1. abc

  2. a

  3. a bc

  4. a+bc

  5. Answer:

    abc

    Solution:

    In Python, the "+" operator acts as a concatenation operator between two strings.


Question: 29 -

Study the following code:

>>>"masterquiz"[5:]  

What will be the output of this code?

Options:
  1. master

  2. quiz

  3. None of these

  4. masterquiz

  5. Answer:

    quiz

    Solution:

    Slice operation is performed on the string.


Question: 30 -

Study the following function:

 
any([5>8, 6>3, 3>1])  

What will be the output of this code?

Options:
  1. Ture

  2. None of these

  3. Invalid code

  4. False

  5. Answer:

    Ture

    Solution not available.