Python Questions

0 votes, 0 avg
403

Python Questions

1 / 15

1.

What will be the datatype of the var in the below code snippet?

var = 10
print(type(var))
var = "Hello"
print(type(var))

2 / 15

2. Which of the following statements are used in Exception Handling in Python?

3 / 15

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

 class test:
     def __init__(self,a):
         self.a=a
 
     def display(self):
         print(self.a)
obj=test()
obj.display()

4 / 15

4. What will be the output of the following Python program?

    def addItem(listParam):

        listParam += [1]

     

    mylist = [1, 2, 3, 4]

    addItem(mylist)

    print(len(mylist))

5 / 15

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

l=[1, 0, 2, 0, 'hello', '', []]
list(filter(bool, l))

6 / 15

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

t = '%(a)s, %(b)s, %(c)s'
t % dict(a='hello', b='world', c='universe')

7 / 15

7. The % operator returns the ___.

8 / 15

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

a=[13,56,17]
a.append([87])
a.extend([45,67])
print(a)

9 / 15

9. Which of the following are valid escape sequences in Python?

10 / 15

10. To add a new element to a list we use which Python command?

11 / 15

11. Which of these is the definition for packages in Python?

12 / 15

12. time.time() returns ________

13 / 15

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

def foo(x):
    x[0] = ['def']
    x[1] = ['abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

14 / 15

14. Consider the results of a medical experiment that aims to predict whether someone is going to develop myopia based on some physical measurements and heredity. In this case, the input dataset consists of the person’s medical characteristics and the target variable is binary: 1 for those who are likely to develop myopia and 0 for those who aren’t. This can be best classified as

15 / 15

15. What will be the output of the following program?

i = 0  
while i < 5:  
    print(i)  
    i += 1  
    if i == 3:  
        break  
else:  
    print(0)  

Your score is

The average score is 35%

0%