Skip to content

Commit e9800c8

Browse files
committed
Python
1 parent 1df10c9 commit e9800c8

7 files changed

+99
-5
lines changed

day38(classes and objects).py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class person:
33
roll=3215
44
cgpa=9.0
55
def info(self):
6-
print(f"{self.name} have {self.cgpa}")
6+
print(f"{self.name} have {self.cgpa}") # self mtlb wo object jiske liye ye method call kiya ja rra h
77
a=person() #objects h
88
b=person()
99
a.name="Kashyap"
@@ -12,4 +12,4 @@ def info(self):
1212
b.name="ALien"
1313
b.cgpa=8
1414
a.info() # method call kra rhe h
15-
b.info()
15+
b.info() #

day39(constructor).py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ class person():
33
# name="Vishal"
44
# roll=3215
55
# cgpa=9.0
6-
def __init__(self,Name,roll): #constructor baabne ka tarika
6+
def __init__(self,Name,roll): #constructor baabne ka tarika
7+
#value initaize karata h and alwys returns none
78
print("i m lazy coder")
89
self.name="Name"
9-
self.roll="roll"
10+
self.roll="roll"#parametrized constructor
1011

1112
def info(self):
12-
print(f"{self.name} have {self.roll}")
13+
print(f"{self.name} have {self.roll}") # default constructor
1314
a=person("Vishal",9.0) #objects h
1415
b=person("alien",9.5)
1516
a.info()

day40(decorators).py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ek function h dusra funnction leta h usko kuch change kr ke reurn kr deta h
2+
3+
def greet(fx):
4+
def mfx(*args,**kwargs): # *args ---arguments leta h as a tuple
5+
# **kwargs --- arguments leta h as a dictonary
6+
print("good morning")
7+
fx(*args,**kwargs)
8+
print("thanks for using thus function ")
9+
return mfx
10+
11+
@greet
12+
13+
def hello():
14+
print("heloo ji")
15+
16+
hello()
17+
# greet (hello)()
18+
@greet
19+
def add(a,b):
20+
print(a+b)
21+
# add()
22+
23+
greet (add)(1,2)

day41(decor2).py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import logging
2+
3+
def log_function_call(func):
4+
def decorated(*args, **kwargs):
5+
logging.info(f"Calling {func.__name__} with args={args}, kwargs={kwargs}")
6+
result = func(*args, **kwargs)
7+
logging.info(f"{func.__name__} returned {result}")
8+
return result
9+
return decorated
10+
11+
@log_function_call
12+
def my_function(a, b):
13+
return a + b

day42(getters setters).py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Person:
2+
def __init__(self, name, age):
3+
self._name = name
4+
self._age = age
5+
6+
# Getter method for getting the name attribute
7+
def get_name(self):
8+
return self._name
9+
10+
# Setter method for setting the name attribute
11+
def set_name(self, name):
12+
self._name = name
13+
14+
# Getter method for getting the age attribute
15+
def get_age(self):
16+
return self._age
17+
18+
# Setter method for setting the age attribute
19+
def set_age(self, age):
20+
if age > 0:
21+
self._age = age
22+
else:
23+
print("Age must be a positive number.")
24+
25+
# Creating an instance of the Person class
26+
person = Person("Alice", 30)
27+
28+
# Using the getter method to get the name attribute
29+
print(person.get_name()) # Output: Alice
30+
31+
# Using the setter method to set the name attribute
32+
person.set_name("Bob")
33+
print(person.get_name()) # Output: Bob
34+
35+
# Using the setter method to set the age attribute with an invalid value (negative number)
36+
person.set_age(-5) # Output: Age must be a positive number.
37+
38+
# Using the setter method to set the age attribute with a valid value
39+
person.set_age(35)
40+
print(person.get_age()) # Output: 35

day43(inheritance).py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Employee:
2+
def __init__(self,name,id):
3+
self.name="name"
4+
self.id=id
5+
6+
def show(self):
7+
print(f"The employee having {self.id} is {self.name}")
8+
9+
class programmer(Employee):
10+
def showlang(self):
11+
print("h=my fav lang is Python")
12+
13+
14+
e=Employee("vishal",420)
15+
e=programmer ("vishal",420)
16+
e.show()
17+
e.showlang()

day44(access modifier).py

Whitespace-only changes.

0 commit comments

Comments
 (0)