Python Programming - Objects - Discussion

Discussion Forum : Objects - General Questions (Q.No. 10)
10.
Consider the following Python code:
class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def birthday(self):
        self.age += 1
If you create an instance of the Student class called john with age 20 and then call john.birthday(), what will be the updated age?
20
21
19
None
Answer: Option
Explanation:
The birthday method increments the age attribute by 1, so after calling john.birthday(), the updated age will be 21.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.