Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Set Instance Attributes

Learn how to initialize instance attributes in a class using the constructor (__init__).

Python practice6 minClasses & Objects FundamentalsBeginnerLast updated April 7, 2026

Problem statement

Create a class named Person. The constructor (__init__) should accept two parameters: name (a string) and age (an integer). Inside __init__, set instance attributes self.name and self.age so they store the provided values. No other behavior is required.

Task

Implement a Person class whose constructor stores provided name and age on each instance.

Examples

Create a person and read attributes

Input

Person('Alice', 30).name

Output

Alice

After constructing Person with 'Alice' and 30, the instance attribute name should be 'Alice'.

Input format

A class constructor invocation of the form Person(name, age).

Output format

Accessing the instance attributes returns the stored values (e.g., Person(...).name or Person(...).age).

Constraints

name will be a string. age will be an integer (can be zero or negative in tests).

Samples

Sample 1

Input

Person('Bob', 0).age

Output

0

The age attribute should be set to 0 for this instance.