Python Programming - Objects - Discussion
Discussion Forum : Objects - General Questions (Q.No. 16)
16.
Consider the following Python code:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def celebrate_birthday(self):
self.age += 1
If you create an instance of the `Person` class called john
with age 30 and then call john.celebrate_birthday()
, what will be the updated age?
Answer: Option
Explanation:
The
celebrate_birthday
method increments the age attribute by 1, so after calling john.celebrate_birthday()
, the updated age will be 31.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers