Skip to content

Commit ffdab44

Browse files
committed
OOP Added
1 parent 9493b2b commit ffdab44

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

basics/OOP/ClassAndObject.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#Creating a Class with some attributes/blueprints for the object
2+
class Character:
3+
name = ""
4+
hp = 100
5+
mp = 50
6+
attack = 12
7+
lv = 1
8+
9+
#Creating an object of the class
10+
character1 = Character()
11+
character2 = Character()
12+
print(character1)
13+
print(character2)
14+
15+
#Accessing the attributes of the object
16+
character1.name = "Night"
17+
character2.name = "Day"
18+
print(character1.name)
19+
print(character2.name)

basics/OOP/Constructor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Create a class named Character
2+
class Character:
3+
def __init__(self,name,hp,mp,attack,lv): #Initializes the attributes of the class
4+
self.name = name
5+
self.hp = hp
6+
self.mp = mp
7+
self.attack = attack
8+
self.lv = lv
9+
print(f"{name}!, Your Character Created")
10+
11+
char1 = Character("Night",100,50,12,1)
12+
print(vars(char1))
13+
char2 = Character("Day",100,50,12,1)
14+
print(vars(char2))
15+
#Accessing the attributes of the object

basics/RealTimeProject/Pokemon/lambda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def fetch_pokemon(name, callback):
1414
# Lambda function as a callback to process and print the data
1515
process_pokemon = lambda data: (
1616
print(f"Name: {data['name']}\nAbilities:"),
17-
print(data['abilities']['ability']['name']) ,
17+
[print(ability['ability']['name']) for ability in data['abilities']],
1818

1919
)
2020

0 commit comments

Comments
 (0)