🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Python OOP: all 15 questions

Quiz: Python OOP · Question 11 of 15

What does this print? (code)

What does this print?

class Student:
    def __init__(self, name, marks):
        self.name = name
        self.marks = marks
    def result(self):
        return "Pass" if self.marks >= 40 else "Fail"

s = Student("Imran", 35)
print(s.name, s.result())
  1. A.Imran Pass
  2. B.Imran Fail
  3. C.Student Fail
  4. D.An error, result() needs an argument
Answer & explanation

Correct answer: Imran Fail

Python passes the object as self automatically, and 35 is below 40.

Can you get the rest right without peeking?

Take the timed Quiz: Python OOP quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →