Python Questions

0 votes, 0 avg
719

Python Questions

1 / 15

1. Which of the following is false regarding conditional statement in Python?

2 / 15

2. Set makes use of __________
Dictionary makes use of ____________

3 / 15

3. What keyword is used in Python to throw exceptions?

4 / 15

4. What will be the output of the following code snippet?

a = "4, 5"
nums = a.split(',')
x, y = nums
int_prod = int(x) * int(y)
print(int_prod)

5 / 15

5. Is Python code compiled or interpreted?

6 / 15

6. Study the following program:

class Std_Name:   
    def __init__(self, Std_firstName, Std_Phn, Std_lastName):  
        self.Std_firstName = Std_firstName  
        self. Std_PhnStd_Phn = Std_Phn  
        self. Std_lastNameStd_lastName = Std_lastName  
   
Std_firstName = "Wick"  
name = Std_Name(Std_firstName, 'F', "Bob")  
Std_firstName = "Ann"  
name.lastName = "Nick"  
print(name.Std_firstName, name.Std_lastName) 

What will be the output of the print statement?

7 / 15

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

8 / 15

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

z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
Z

9 / 15

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

    x = 50

    def func(x):

        print('x is', x)

        x = 2

        print('Changed local x to', x)

    func(x)

    print('x is now', x)

10 / 15

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

for i in range(5):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

11 / 15

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

    def func(a, b=5, c=10):

        print('a is', a, 'and b is', b, 'and c is', c)

     

    func(3, 7)

    func(25, c = 24)

    func(c = 50, a = 100)

12 / 15

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

13 / 15

13. What will be the output of the following Python code if the input entered is 6?

valid = False
while not valid:
    try:
        n=int(input("Enter a number"))
        while n%2==0:
            print("Bye")
        valid = True
    except ValueError:
        print("Invalid")

14 / 15

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

15 / 15

15. What is the order of namespaces in which Python looks for an identifier?

Your score is

The average score is 40%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top