Programming/Python

[Python] ํŒŒ์ด์ฌ sys.stdin.readline() ์ž…๋ ฅ ๋ฐ›๊ธฐ : ์‹œ๊ฐ„ ์ดˆ๊ณผ ํ•ด๊ฒฐ, ์ž…์ถœ๋ ฅ ์†๋„ ๊ฐœ์„ 

728x90

 

๐Ÿค” input() ๋Œ€์‹  sys.stdin.readline() ์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

ํ•œ๋‘์ค„ ์ž…๋ ฅ๋ฐ›๋Š” ๋ฌธ์ œ๋“ค์€ input()์„ ์‚ฌ์šฉํ•ด๋„ ๊ดœ์ฐฎ์„ ์ˆ˜ ์žˆ์ง€๋งŒ,

์—ฌ๋Ÿฌ์ค„ ๋˜๋Š” ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ์ž…๋ ฅ ๋ฐ›๋Š” ๊ฒฝ์šฐ์—๋Š” input()์€ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

์ด๋Ÿด ๋•Œ, sys.stdin.readline() ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค

 

์ฝ”๋“œ์— ๊นŠ์€ ๋ณต์‚ฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ณต์‚ฌ ๋ฐฉ๋ฒ• ์„ ํƒ์œผ๋กœ๋„ ์‹คํ–‰ ์‹œ๊ฐ„์„ ๋‹จ์ถ•์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค! ๋‹ค์Œ ๊ธ€์— ์ •๋ฆฌํ•ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค

๐Ÿ“Œ  https://codesyun.tistory.com/198

 

[Python] ํŒŒ์ด์ฌ ๋ฆฌ์ŠคํŠธ ๋ณต์‚ฌ : ์‹œ๊ฐ„ ์ดˆ๊ณผ ํ•ด๊ฒฐ, ๊นŠ์€ ๋ณต์‚ฌ์™€ ์–•์€ ๋ณต์‚ฌ, copy, deepcopy, slicing, 2์ฐจ์› ๋ฆฌ

๋”๋ณด๊ธฐ ๋ฐฑ์ค€ ํ’€์ด๋ฅผ ํ•˜๋‹ค ๋ฆฌ์ŠคํŠธ๋ฅผ ๊นŠ์€ ๋ณต์‚ฌํ•  ๋•Œ, deepcopy()๋ฅผ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ๊ฐ€ slicing์„ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ๋ณด๋‹ค 7๋ฐฐ ์ด์ƒ์˜ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ ๊ฒƒ์„ ํ™•์ธํ•˜๊ณ  ์ •๋ฆฌํ•ด๋ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค! ๊ฐ€๋œฉ์ด๋‚˜

codesyun.tistory.com

 

 

 

 

 


๐Ÿ“Œ sys.stdin.readline() ์‚ฌ์šฉ๋ฒ•

 

1. ๋ฌธ์ž์—ด ์ž…๋ ฅ ๋ฐ›์„ ๋•Œ

import sys

str = sys.stdin.readline()

- ๋ฌธ์ž์—ด์— ๊ฐœํ–‰๋ฌธ์ž(\n)์ด ๊ธฐ๋ณธ์œผ๋กœ ์ถ”๊ฐ€๋จ

 

 

2. ํ•œ ๊ฐœ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์„ ๋•Œ

import sys

str = int(sys.stdin.readline())

 

 

3. ์ •ํ•ด์ง„ ๊ฐœ์ˆ˜์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์„ ๋•Œ

import sys

a, b = map(int, sys.stdin.readline().split())

 

 

4. ์ž„์˜์˜ ๊ฐœ์ˆ˜์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์„ ๋•Œ

import sys

data = list(map(int, sys.stdin.readline().split()))

 

 

5. N์ค„์˜ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ ๋ฐ›์•„ ๋ฆฌ์ŠคํŠธ์— ์ €์žฅํ•  ๋•Œ

import sys

n = int(sys.stdin.readline())
data = [sys.stdin.readline().strip() for i in range(n)]

 

 

 

 

 

 

 

728x90