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
'CS > Python' 카테고리의 다른 글
[Python] 파이썬 올림, 내림, 반올림 총정리 (1) | 2024.07.15 |
---|---|
[Python] string 유용한 함수 (0) | 2024.01.05 |
[Python 오류] import cv2 안 될 때, install cv2 (0) | 2023.06.04 |
[Python] float에서 \n이 출력되는 현상 (???) (0) | 2023.04.05 |
[Python 오류] pip install 안 될 때 (0) | 2022.12.16 |
댓글