What Will Be The Output Of The Following Python Codep Pre #1090
What will be the output of the following Python code?</p> <pre><code class="language-python"> class stud: def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) stud1 = stud(34, 'S') stud1.age=7 print(hasattr(stud1, 'age')) </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs109 Python. It can also be found in gs gs109 Classes and Objects - Python Classes and Objects - Quiz No.3.
What will be the output of the following Python code?
class stud: def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) stud1 = stud(34, 'S') stud1.age=7 print(hasattr(stud1, 'age'))
Error as age isn’t defined
True
False
7