Skip to content

Commit 247858a

Browse files
committed
240212 BOJ I/O 처리방법 추가
1 parent a3ff426 commit 247858a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: BOJ/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,43 @@ sample_str = sys.stdin.readline().rstrip()
120120
```
121121

122122
- 위 코드의 원리
123+
124+
- (1) `input()` vs `sys.stdin.readline()` 차이점
125+
126+
- `input()` 은 입력된 값의 개행 문자(\n)를 자동으로 삭제하여 리턴 (=`rstrip()` 의 기능)
127+
128+
```python
129+
>>> a = input()
130+
apple
131+
>>> a
132+
'apple'
133+
```
134+
135+
- `sys.stdin.readline()` 은 입력된 값의 개행 문자(\n)를 포함해서 그대로 리턴
136+
137+
- 따라서 개행 문자를 제거하려면 처음부터 typeint 로 받아서 개행 문자 없게 만들거나, 개행 문자 제거해주는 `rstrip()` 을 써야함
138+
139+
```python
140+
import sys
141+
142+
a = sys.stdin.readline()
143+
apple
144+
>>> a
145+
'apple\n'
146+
```
147+
148+
```python
149+
>>> a = sys.stdin.readline().rstrip()
150+
apple
151+
>>> a
152+
'apple'
153+
```
154+
155+
```python
156+
>>> a = int(sys.stdin.readline())
157+
5
158+
>>> a
159+
5
160+
```
161+
162+

0 commit comments

Comments
 (0)