Python interview questions part 52

Python interview questions part 52

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What is the output of the following code ? class Count: def __init__(self, count = 0): self.__count = count c1 = Count(2)c2 = Count(2)print(id(c1) == id(c2), end = " ") s1 = "Good"s2 = "Good"print(id(s1) == id(s2))

Correct Answer is : False True

2. What is the output of the following code ? class Name: def __init__(self, firstName, mi, lastName): self.firstName = firstName self.mi = mi self.lastName = lastName firstName = "John"name = Name(firstName, 'F', "Smith")firstName = "Peter"name.lastName = "Pan"print(name.firstName, name.lastName)

Correct Answer is : John Pan

3. What function do you use to read a string?

Correct Answer is : input(“Enter a string”)

4. Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space)

Correct Answer is : ___345.355

5. What is the output of the following? print("abc DEF".capitalize())

Correct Answer is : Abc def

6. What is the output of the following? print("abc. DEF".capitalize())

Correct Answer is : Abc. def

7. What is the output of the following? print("abcdef".center())

Correct Answer is : error

8. What is the output of the following? print("abcdef".center(0))

Correct Answer is : error

9. What is the output of the following? print('*', "abcdef".center(7), '*')

Correct Answer is : * abcdef *

10. What is the output of the following? print('*', "abcdef".center(7), '*', sep='')

Correct Answer is : * abcdef*

11. What is the output of the following? print('*', "abcde".center(6), '*', sep='')

Correct Answer is : *abcde *

12. What is the output of the following? print("abcdef".center(7, 1))

Correct Answer is : error

13. What is the output of the following? print("abcdef".center(7, '1'))

Correct Answer is : 1abcdef

14. What is the output of the following? print("abcdef".center(10, '12'))

Correct Answer is : error

15. What is the output of the following? print("xyyzxyzxzxyy".count('yy'))

Correct Answer is : 2

16. What is the output of the following? print("xyyzxyzxzxyy".count('yy', 1))

Correct Answer is : 2

17. What is the output of the following? print("xyyzxyzxzxyy".count('yy', 2))

Correct Answer is : 1

18. What is the output of the following? print("xyyzxyzxzxyy".count('xyy', 0, 100))

Correct Answer is : 2

19. What is the output of the following? print("xyyzxyzxzxyy".count('xyy', 2, 11))

Correct Answer is : 0

20. What is the output of the following? print("xyyzxyzxzxyy".count('xyy', -10, -1))

Correct Answer is : 0

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon