Skip to content

Commit bcd6166

Browse files
authored
Add files via upload
1 parent aa492e0 commit bcd6166

57 files changed

Lines changed: 1483 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

13_oop/Edcorner/01.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import datetime
2+
3+
for name in sorted(datetime.__dict__):
4+
print(name)
5+
6+
"""
7+
MAXYEAR
8+
MINYEAR
9+
UTC
10+
__all__
11+
__builtins__
12+
__cached__
13+
__doc__
14+
__file__
15+
__loader__
16+
__name__
17+
__package__
18+
__spec__
19+
date
20+
datetime
21+
datetime_CAPI
22+
sys
23+
time
24+
timedelta
25+
timezone
26+
tzinfo
27+
"""

13_oop/Edcorner/02.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Implement a function called stick( ) that takes any number of bare arguments and return an object of type
3+
str being a concatenation of all arguments of type str passed to the function with the '#' sign
4+
"""
5+
def stick(*args):
6+
args = [arg for arg in args if isinstance(arg, str)]
7+
8+
result="#".join(args)
9+
return result
10+
11+
print(stick('sport', 'summer'))
12+
print(stick(3, 5, 7))
13+
print(False, 'time', True, 'workout', [], 'gym')
14+
15+
16+
"""
17+
sport#summer
18+
19+
False time True workout [] gym
20+
21+
"""

13_oop/Edcorner/03.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Implement a function called dispiay_info() which prints the name of the company and
3+
if the user also passes an argument named price , it prints the price
4+
"""
5+
6+
def display_info(company, **kwargs):
7+
print(f"Company name: {company}")
8+
if 'price' in kwargs:
9+
print(f"Price: $ {kwargs['price']}")
10+
11+
12+
display_info(company="AI BioTech", price=5000)
13+
14+
"""
15+
Company name: AI BioTech
16+
Price: $ 5000
17+
"""

13_oop/Edcorner/04.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
create a class and print the class name
3+
"""
4+
5+
class Vehicle:
6+
pass
7+
8+
9+
print(Vehicle.__name__)
10+
11+
"""
12+
Vehicle
13+
"""

13_oop/Edcorner/05.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
""" create a class and Display all _dict_ attribute keys of the class """
2+
3+
class Container:
4+
pass
5+
6+
print(Container.__dict__.keys())
7+
8+
""" dict_keys(['__module__', '__dict__', '__weakref__', '__doc__']) """

13_oop/Edcorner/06.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
1. Create a Container class. Display the value of the module attribute of the Container class to the console.
3+
4+
2. Create an instance of the Container class and assign it to the container variable. Print the type of
5+
container variable to the console.
6+
7+
3. print the _class_ attribute value of the container instance
8+
9+
4. display the type of dictionary attribute _dict_ for the Container class and for the container instance.
10+
"""
11+
12+
class Container:
13+
pass
14+
#-------------------------------------------
15+
# 1
16+
print(Container.__module__) ## __main__
17+
#-------------------------------------------
18+
# 2
19+
container= Container()
20+
print(type(container)) ## <class '__main__.Container'>
21+
#-------------------------------------------
22+
# 3
23+
print(container.__class__) ## <class '__main__.Container'>
24+
#-------------------------------------------
25+
# 4
26+
print(Container.__dict__)
27+
## {'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Container' objects>, '__weakref__': <attribute '__weakref__' of 'Container' objects>, '__doc__': None}
28+
29+
print(container.__dict__)
30+
## {}
31+
32+

13_oop/Edcorner/07.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Define a simple class named Model.
3+
Then create an instance of this class named model.
4+
Using the built-in function isinstance( ) check if the model is an instance of the Model class. Print the result to the console.
5+
"""
6+
7+
class Model:
8+
pass
9+
10+
model=Model()
11+
print(isinstance(model, Model)) ## True

13_oop/Edcorner/08.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
Implement a class named Brandname. In the Phone class, define a class attribute named brand
3+
and set its value to 'Amazon'. Then, using dot notation and print ( ) function, display the value of the
4+
brand attribute of the Phone class to the console.
5+
"""
6+
7+
class Brandname:
8+
brand = 'Amazon'
9+
10+
print(Brandname.brand) ## Amazon

13_oop/Edcorner/09.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""use the built-in functions getattr() and print () to display the values of the given attributes of the class"""
2+
3+
class Phone():
4+
5+
brand= "Apple"
6+
model= "Iphone X"
7+
8+
9+
print(getattr(Phone, 'brand'))
10+
print(getattr(Phone, 'model'))
11+
12+
13+
"""
14+
Apple
15+
Iphone X
16+
"""

13_oop/Edcorner/10.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
""" Using dot notation, modify the value of the attributes """
2+
3+
class Phone:
4+
brand= "Apple"
5+
model= "Iphone X"
6+
7+
Phone.brand= "Samsung"
8+
Phone.model= "Galaxy"
9+
10+
print(f"brand: {Phone.brand}")
11+
print(f"model: {Phone.model}")
12+
13+
"""
14+
brand: Samsung
15+
model: Galaxy
16+
"""

0 commit comments

Comments
 (0)