이게 대체 뭐더냐
코테 스터디를 하는데 다들 input이 아니라 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.
- prompt에 입력한 인자에서 개행 문자를 없애고, string으로 변환을 한 후 return 해 줌
sys.stdinFile objects used by the interpreter for standard input, output and errors:
stdin is used for all interactive input (including calls to input());
- 파이썬 인터프리터가 표준 입력, 표준 출력, 표준 에러에 사용하는 파일 객체(file object)
stdin=> 모든 대화형 입력(input()함수 호출을 포함한 입력)에 사용됨
- 파이썬 환경에서 텍스트 파일을 읽고 쓸 수 있도록 지원하는 객체
- 파일과 관련된 작업(읽기, 쓰기, 추가 등)을 수행할 수 있도록 파이썬이 제공하는 도구
input vs. sys.stdin| input() | sys.stdin |
|---|---|
| - 한 줄씩 입력을 받을 때 사용 | - 파일이나 대량의 입력을 처리할 때 사용 |
| - 입력이 끝날 때 엔터를 눌러야 다음으로 넘어감 | - 여러 줄 입력을 한 번에 읽어올 수 있음 |
| - 느릴 수 있음 | - 더 빠르고 효율적 |
readline()\n)가 같이 입력됨strip()으로 앞, 뒤의 공백을 제거해야 함