Skip to content

Instantly share code, notes, and snippets.

@EeeasyCode
Created January 2, 2023 07:09
Show Gist options
  • Save EeeasyCode/3b67bbae96002bb993a53173678ce5a5 to your computer and use it in GitHub Desktop.
Save EeeasyCode/3b67bbae96002bb993a53173678ce5a5 to your computer and use it in GitHub Desktop.
Enhanced I/O
import sys
input = sys.stdin.readline
print = sys.stdout.write
@EeeasyCode
Copy link
Author

EeeasyCode commented Jan 2, 2023

input()은 개행문자 "\n"까지 읽어들이기 때문에 .rstrip()등으로 지워주어야 하고,

input = sys.stdin.readline

n = input()              # "1"을 입력 할 때,

print(list(n))           # ['1', '\n']
print([int(n)])          # [1]
print(list(n.rstrip()))  # ['1'] 

print()는 출력 방식이 다음과 같이 바뀌어 버린다.

print = sys.stdout.write

print("%s\n" % "123")  # 123
print("%s\n" % ("12" + "3"))  # 123
print("%d + %d = %d\n" % (1, 2, 1 + 2))  # 1 + 2 = 3 

또한, 줄바꿈이 사라지기 때문에 직접 처리해주어야 한다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment