-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path019Classes.py
More file actions
59 lines (41 loc) · 1.27 KB
/
019Classes.py
File metadata and controls
59 lines (41 loc) · 1.27 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
how_many_s = [{'s': False}, "sassafrass", 18, ["a", "c", "s", "d", "s"]]
for element in how_many_s:
if hasattr(element, "count"):
print(element.count("s"))
# # # # # # # # #
class Circle:
pi = 3.14
def __init__(self, diameter):
print("Creating circle with diameter {d}".format(d=diameter))
# Add assignment for self.radius here:
self.radius = diameter/2
def circumference(self):
return 2 * self.pi * self.radius
medium_pizza = Circle(12)
teaching_table = Circle(36)
round_room = Circle(11460)
print(medium_pizza.circumference())
print(teaching_table.circumference())
print(round_room.circumference())
### dir() method on objects
print(dir(5))
def this_function_is_an_object():
pass
print(dir(this_function_is_an_object))
### __repr__(self) method takes no parameter and return only string
class Circle:
pi = 3.14
def __init__(self, diameter):
self.radius = diameter / 2
def area(self):
return self.pi * self.radius ** 2
def circumference(self):
return self.pi * 2 * self.radius
def __repr__(self):
return "Circle with radius {radius}".format(radius=self.radius)
medium_pizza = Circle(12)
teaching_table = Circle(36)
round_room = Circle(11460)
print(medium_pizza)
print(teaching_table)
print(round_room)