My Report

Python String Test – 4


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. To check whether string s1 contains another string s2, use ________

2. To return the length of string s what command do we execute?

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

4. If a class defines the __str__(self) method, for an object obj for the class, you can use which command to invoke the __str__ method.

5. Suppose x is 345.3546, what is format(x, "10.3f") (_ indicates space).

6. Suppose i is 5 and j is 4, i + j is same as ________

7. What will be the output of the following Python 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))

8. What will be the output of the following Python 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)

9. To retrieve the character at index 3 from string s="Hello" what command do we execute (multiple answers allowed)?

10. What is "Hello".replace("l", "e")?


 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.