res = [1, 2, 3, 4]
max(res) # 4
min(res) # 1
res[len(res)//2] # len = 4, // 2 int 나누기
4/2 = 2.0
4//2 = 2
5/2 = 2.5
5//2 = 2
max(3, 2) => 3
함수가 특정 값을 반환할 때 최댓값을 구하고 싶을 때
def func(x):
return x ** 2
res = 0
for i in range(10):
res = max(res, func(i))
iter() 와 next()
- next() : 반복 가능 객체의 다음 요소를 반환하는 함수이다
- iter() : 반환값을 받으려면 리스트나 for문을 도움을 받아야 가능, 반복 가능한 객체의 다음 요소를 꺼내는 것
iter_x=iter([1,2,3,4,5])
print(list(iter_x)) # [1,2,3,4,5]
print(next(iter_x) ) # 1
for _ in range(5):
print(next(iter_x)) # 1 \\n 2 \\n 3 \\n 4 \\n 5
.join
- .join : 리스트를 문자열로 특정 간격 설정에 따라만들어주는 것
s = [1,2,3,4,5]
print(' '.join(map(str,s))) # 1 2 3 4 5