-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Example15.py
More file actions
41 lines (33 loc) · 1.08 KB
/
Class_Example15.py
File metadata and controls
41 lines (33 loc) · 1.08 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
"""
Represent the following data in the form of class
cityName = ['Michigan', 'Ann Arbor', 'Pittsburgh', 'Mars', 'New York']
populations = [680250, 117070, 304391, 1683, 8406000]
states = ['MI', 'MI', 'PA' , 'PA', 'NY']
"""
class USMetric:
"""
Class that describes the population, state name and the city name
"""
def __init__(self, city, population, state):
"""
Initializes the variable
"""
self.city= city
self.population = population
self.state = state
def __repr__(self):
"""
representing in the form of string
:param self:
:return:
"""
return f"USMetric({self.city},{self.population},{self.state})"
cityName = ['Michigan', 'Ann Arbor', 'Pittsburgh', 'Mars', 'New York']
populations = [680250, 117070, 304391, 1683, 8406000]
states = ['MI', 'MI', 'PA' , 'PA', 'NY']
tuple1 = zip(cityName, populations, states)
usmetric_list = list()
for tuple_ in tuple1:
city, population, state = tuple_
usmetric_list.append(USMetric(city, population, state))
print(usmetric_list)