Change the value by objects

Hi
In the below coding why the function is used
#change the value by objects
class myclass:
def init(self, name, age):
self.name=name
self.age=age
def myfunction(self):
print('my name is '&self.name)
#creating object
m1 = myclass(‘sumit’,25)
m1.name
m1.age

#changing the age using object
m1.age=26

m1.age

it be also written as

#change the value by objects
class myclass:
def init(self, name, age):
self.name=name
self.age=age
#creating object
m1 = myclass(‘sumit’,25)
m1.name
m1.age

#changing the age using object
m1.age=26

m1.age