Python Questions

0 votes, 0 avg
543

Python Questions

1 / 15

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

string = "my name is x"
for i in string.split():
    print (i, end=", ")

2 / 15

2. 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")

3 / 15

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

a = [1, 2, 3]
a = tuple(a)
a[0] = 2
print(a)

4 / 15

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

5 / 15

5. Which of the following is the use of id() function 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 these about a frozenset is not true?

8 / 15

8. Which of the following Python code will print True?

a = foo(2)
b = foo(3)
print(a < b)

9 / 15

9. Which of the following is true for variable names in Python?

10 / 15

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

numbers = (4, 7, 19, 2, 89, 45, 72, 22)
sorted_numbers = sorted(numbers)
even = lambda a: a % 2 == 0
even_numbers = filter(even, sorted_numbers)
print(type(even_numbers))

11 / 15

11. Which of the following character is used to give single-line comments in Python?

12 / 15

12. The list.index(x[, start[, end]]) is used to ___.

13 / 15

13. What will be the value of ‘result’ in following Python program?

list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
result.extend(i for i in list1 if i not in (list2+list3) and i not in result)
result.extend(i for i in list2 if i not in (list1+list3) and i not in result)
result.extend(i for i in list3 if i not in (list1+list2) and i not in result)

14 / 15

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

15 / 15

15. Which of the following best describes inheritance?

Your score is

The average score is 36%

0%