본문 바로가기
ETC

[Python] input(), sys.stdin.readline()

by 나른한 사람 2021. 2. 22.

아래쪽 결과가 input()으로 입력을 받았을 때, 위쪽이 sys.stdin.readline()으로 입력 받았을 때의 걸린 시간이다.

 

input()

 If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.

docs.python.org/3/library/functions.html#input

 

Built-in Functions — Python 3.9.2 documentation

Built-in Functions The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order. abs(x) Return the absolute value of a number. The argument may be an integer, a floating poin

docs.python.org

 - 인자가 있을 경우, 표준 출력에 개행문자 없이 쓰여진다.

 - 이 함수는 입력으로부터 한 줄을 읽고, string으로 변환, 개행문자를 삭제하고 반환한다.

 

input() 함수는 입력 받은 line을 string으로 변환, 개행문자를 삭제, 표준출력에 기록까지 수행해서 상대적으로 느린듯 함.

 

여러 행을 입력받아야 할 경우에는 input() 함수보다는 sys.stdin.readline()을 사용하는게 좋음.

 

댓글