input() # 문자열만 입력을 받음
x = input() # 'koo' -> 'koo'
x = int(input()) # '9' -> 9
L = ['1', '2', '3', '4']
L_int = map(int, L) # [1, 2, 3, 4]
1 2 3 4
input() # '1 2 3 4'
input().split() # ['1', '2', '3', '4']
map(int, input().split()) # map instance가 생성이 돼
list(map(int, input().split())) # [1, 2, 3, 4]
a, b라는 값을 한줄에 입력받으려 함
1 2
a, b = map(int, input().split())
a = 1, b = 2
python 값을 여러 개 반환할 수 있는데, 여러 개 반환하면 Tuple로 반환됨
def func():
a, b = map(int, input().split())
return a, b # 반환값이 튜플이 됨
n, m = map(int, input().split()) # n, m 초기화
1 2 -> '1 2' -> ['1', '2'] -> [1, 2] -> 할당
[[0, 0, 0],
[1, 1 ,1],
[0, 0, 0]]
list comprehension
graph = [list(map(int, input().split())) for _ in range(3)]
n, m이 나오고
다음줄부터 graph가 입력으로 들어온다
ex.
3 3
1 1 1
0 0 0
2 2 2
n, m = map(int, input().split())
graph = [list(map(int, input().split())) for _ in range(3)]
python이 좀 느린 편
import sys
read = sys.stdin.readline
# '1 2 3'
input() # '1 2 3'
read() # '1 2 3\\n'
# 그냥 쓰는 경우 -> default 공백이랑 개행
read().rstrip() # '1 2 3'
read().lstrip() # '1 2 3\\n'
read().strip() # '1 2 3'
read().lstrip('1') # ' 2 3\\n'
# split이랑 쓰는 경우
# '1 2 3'
read().split() # ['1', '2', '3']
# 입력값이 붙어서 나오는 경우
###
#..
##.
# 개행 문자가 없애려고 사용
list(read()) # ['#', '#', '#', '\\n']
list(read().rstrip()) # ['#', '#', '#']
graph = [list(read().rstrip()) for _ in range(3)]
# 출력 형식 : 1 2 3 4
res = [1, 2, 3, 4]
print(*res)
# 2차원 배열
graph = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
for row in graph:
print(*row)
'''
결과
1 2 3
4 5 6
7 8 9
'''