본문 바로가기
CS/Python

[Python] 파이썬 입력 정리

by Code Song 2023. 4. 5.

1. input().split()

input으로 받아서 tab, space, new line 기준 split

 

단 split은 매개변수를 하나로만 인식함!
aa,bb@cc를 나누고 싶을 때 input().split(',@') 하지 못한다.

그럴 때는 2가지 방법이 있다.

 

(1) 치환 후 사용

(2) 정규식 사용

 

2. sys.stdin.readline()

input보다 빠르다

쉽게 쓰기 위하여 input = sys.stdin.readline을 해주면 똑같이

a, b = map(int, input().split())처럼 사용할 수 있다.

 

주의!

text = sys.stdin.readline()이라면 개행문자까지 같이 받는다.

깔끔하게 쓰고 싶다면 뒤에 sys.stdin.readline().rstrip()으로 쓰자

 

3. map

a, b = map(int, input().split())

 

 


3

89 23 5

n = int(input())

data = list(map(int, input().split()))

 

3 5 7

n, m, k = map(int, input().split())

 

sys.stdin.readline().rstrip() #remove /n

댓글