str의 .split() attribute는 양 옆의 공백을 기본적으로 제거하기 때문에 두 코드 모두 기능상 문제가 없습니다.
'1 2 3'.split()
' 1 2 \n3 \n '.split()
위 2 줄의 코드를 실행해보세요
15552번 - 빠른 A+B
str의 .split() attribute는 양 옆의 공백을 기본적으로 제거하기 때문에 두 코드 모두 기능상 문제가 없습니다.
'1 2 3'.split()
' 1 2 \n3 \n '.split()
위 2 줄의 코드를 실행해보세요
https://docs.python.org/3.12/l...
If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace.
.split()으로만 실행할 경우 양 옆의 공백을 제거하고 중간의 공백은 연속되어 있을 경우 하나로 취급하여 split하게 됩니다.
따라서, 개행문자가 제거되어 문제가 없습니다. (개행문자도 공백으로 간주됩니다)
아 개행문자도 공백으로 간주되는군요! 감사합니다.
댓글을 작성하려면 로그인해야 합니다.
0124yongsang 2년 전
아래의 두 코드를 제출할 경우 모두 정답이라고 나옵니다.
sys.stdin.readline() 통해 값을 입력 받을 경우 "개행문자"까지 입력 받는다고 알고 있습니다.
따라서 "/n" 를 제거하기 위해 strip함수를 사용한 코드만이 맞다고 생각되어 질문 남깁니다.