(파이썬) TypeError: slice indices must be integers or None or have an __index__ method
Error List

(파이썬) TypeError: slice indices must be integers or None or have an __index__ method

728x90

Traceback (most recent call last):
    front_n = n[ : len(n) / 2]
TypeError: slice indices must be integers or None or have an __index__ method

위 경우이 len(n) / 2 는 float 형으로 반환되기 때문에 다음과 같은 오류가 발생한다.

배열을 slice 해줄 때는 꼭 int 형으로 적어 주어야 한다.

그래서 이 경우에는  len(n) // 2 로 적으면 몫을 반환하게 되어 int 형이 된다.

728x90