Skip to main content

Write a program to implement to show the use of an access specifier.

· One min read
Kaustubh Kulkarni
file.py
class User:
def __init__(self, name, age):
self.usrName = name
self.usrAge = age
def displayAge(self):
print("Age: ", self.usrAge)
obj = User("ABC", 20)
print("Name: ", obj.usrName)
obj.displayAge()

output:

Output
Name: ABC
Age: 20