-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLASS METHOD EXAMPLE 2.py
More file actions
29 lines (23 loc) · 983 Bytes
/
CLASS METHOD EXAMPLE 2.py
File metadata and controls
29 lines (23 loc) · 983 Bytes
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
class defenders:
saga = "The Defenders"
def __init__(self, name, title):
self.name = name
self.title = title
def details(self):
print("Name: ", self.name , "Title: ", self.title, "Saga: ", defenders.saga)
## class method to update the defenders name I am not gonna add it into the code rather keep it commented out
# @classmethod
# def update_saga(cls, new_saga):
# cls.saga = new_saga
@classmethod
def from_string(cls, info):
name, title = info.split("-") # takes like this Matt Murrdock- daredevil
name = name.title()
obj = cls(name, title) # here i am splitting this like this (matt murrdock, daredevil)
return obj
#################### command line ################################
def1 = defenders("Frank Castle", "The Punisher")
def2 = defenders.from_string("matt murrdock-Daredevil")
## to the printeeeeeeeeeeeeeeeeee
def1.details()
def2.details()