Python

[Python] sys.stdin

슈퍼짱짱 2019. 8. 5. 14:08
반응형

input()에 비해 sys.stdin이 시간을 줄여준다고 한다.

 


>>> import sys

 

1. stdin : ^z 까지 입력

>>> a = sys.stdin

>>> 123

>>> 222

...

^z

>>> a

<_pydev_bundle.pydev_stdin.StdIn object at 0x0000022B1BAA4E80>

 

2. readline()

>>> a = sys.stdin.readline()

>? 123

>>> a

'123\n'

 

>>> a = sys.stdin.readline()

>? 123

... 456

>>> a

'123\n456\n'

 

- strip() : 맨 뒤 개행문자 자동 삭제

>>> a = sys.stdin.readline().strip()

>? 123

>>> a

'123'

 

- split()

>>> a = sys.stdin.readline().split()

>? 123

... 456

>>> a

['123','456']

 

>>> a = sys.stdin.readline().split("\n)

>? 123

... 456

>>> a

['123','456','']

 

 

반응형