python/클래스
메서드3
june__Park
2021. 3. 21. 04:47
class Ex03:
def test1(self, lst):
cnt = 0
for i in range(len(lst)):
if lst[i]%4 == 0:
cnt += 1
return cnt
def test2(self, lst):
temp = []
for i in range(len(lst)):
if lst[i]%4 == 0:
temp.append(lst[i])
return temp
e = Ex03()
lst = [87, 12, 21, 56, 100]
# 문제 1) 4의 배수의 개수를 리턴해주는 메서드
print(e.test1(lst))
# 문제 2) 4의 배수만 리스트 타입으로 리턴해주는 메서드
temp = e.test2(lst)
print(temp)