Python Questions

0 votes, 0 avg
612

Python Questions

1 / 15

1. Study the following code:

x = [‘XX’, ‘YY’]
for i in a:
i.lower()
print(a)

What will be the output of this program?

2 / 15

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

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

3 / 15

3. 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')

4 / 15

4. 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?

5 / 15

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

6 / 15

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

places = ['Bangalore', 'Mumbai', 'Delhi']

places1 = places places2 = places[:]
places1[1]="Pune" places2[2]="Hyderabad" print(places)

7 / 15

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

8 / 15

8.  Python supports the creation of anonymous functions at runtime, using a construct called __________

9 / 15

9. What is the order of precedence in python?

10 / 15

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

    def printMax(a, b):

        if a > b:

            print(a, 'is maximum')

        elif a == b:

            print(a, 'is equal to', b)

        else:

            print(b, 'is maximum')

    PrintMax(3, 4)

11 / 15

11. Which of the following types of loops are not supported in Python?

12 / 15

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

def solve(a):
   a = [1, 3, 5]
a = [2, 4, 6]
print(a)
solve(a)
print(a)

13 / 15

13. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?

14 / 15

14. What is called when a function is defined inside a class?

15 / 15

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

x = "abcdef"
i = "a"
while i in x:
    x = x[:-1]
    print(i, end = " ")

Your score is

The average score is 37%

0%

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