File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -120,3 +120,43 @@ sample_str = sys.stdin.readline().rstrip()
120
120
```
121
121
122
122
- 위 코드의 원리
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
+ - 따라서 개행 문자를 제거하려면 처음부터 type 을 int 로 받아서 개행 문자 없게 만들거나, 개행 문자 제거해주는 `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
+
You can’t perform that action at this time.
0 commit comments