← 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())
- A.Imran Pass
- B.Imran Fail
- C.Student Fail
- 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 →