-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworking_with_class_method.py
More file actions
39 lines (28 loc) · 1.06 KB
/
working_with_class_method.py
File metadata and controls
39 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class School:
location = "Bangalore"
def __init__(self, first_name, last_name, age):
self.first_name = first_name
self.last_name = last_name
self.age = age
def info(self):
return f"student name {self.first_name} {self.last_name} and his age {self.age}"
def add_location(self):
return f"student name {self.first_name} {self.last_name} and his age {self.age} {self.location}"
@classmethod
def update_age(cls, new_age):
cls.age = new_age
@classmethod
def split_names(cls, new_data):
first_name = new_data[0]
last_name = new_data[1]
age = new_data[2]
return cls(first_name, last_name, age)
class Tutions(School):
def __init__(self, first_name, last_name, age, location):
super().__init__(first_name, last_name, age)
self.age = age
self.location = location
def result(self):
return f'Student name -> {self.first_name} {self.last_name} and {self.location} {self.age}'
ini = Tutions('ram', 'gut', '28', "banaglore")
print(ini.info())