Logo

Python Questions Set 157:

Quiz Mode

def fun(n):

    n+=n

    return

print(fun(5))

Solution:

x = '123463'

d = x[1] + x[4]

print(d)

1
2
3
4

Solution:

Numbers with the 0x prefix are treated as hexadecimal numbers.

1
2
3
4
5

Solution:

What is the output of the following code:

L = ['s', 't', 'u', 'v']

print("".join(L))

1
2
3
4

Solution:

What will be the output of the following Python code?

print('xyyzxxyxyy'.lstrip('xyy'))

1
2
3
4

Solution:

 

Which of these is a private data field?

def Demo:
def __init__(self):
   __a = 1
   self.__b = 1
   self.__c__ = 1
   __d__= 1

1
2
3
4

Solution:

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)

1
2
3
4

Solution:

 time.struct_time(tm_year=2017, tm_mon=6, tm_mday=25, tm_hour=18, tm_min=26, tm_sec=6, tm_wday=6, tm_yday=176, tm_isdst=0)
Code: 


 

import time
t=time.localtime()
print(t)



 To extract only the year from this, we can use the function: 

1
2
3
4

Solution:

What will be the output of the following code?

a = ('python', 'java', 'ruby', 'css', 'html')
b = ('abekus',) * 5
c = b[3]
print(c)
print(b)

1
2
3
4

Solution: