이것저것
python 한 번에 여러 값 입력받기 본문
1. input() 와 list()이용
new = input()
result = list(new)
print(result)
>>> 1 2 3 4
>>> ['1', ' ', '2', ' ', '3', ' ', '4']
2. input(), list(), str() 이용
new = input()
result = list(str(new))
print(result)
>>> apple
>>> ['a', 'p', 'p', 'l', 'e']
3. input().split()이용
new = input().split()
print(new)
>>> hi everyone 1 2 3 4
>>> ['hi', 'everyone', '1', '2', '3', '4']
new = input().split(':')
print(new)
>>> 1:2:34:5
>>> ['1', '2', '34', '5']
4. 변수에 저장
a,b,c = input().split()
print(a)
print(b)
print(c)
>>> 1 2 3
>>> 1
2
3
5. list(map( 함수, 리스트))
s = [5.4, 1.3, 8.4]
new_list = list(map(int,s))
print(new_list)
>>> [5, 1, 8]
6. list(map(int, input().split()))
s = list(map(int, input().split(' ')))
print(s)
>>> [5, 1, 8, 3]
s = list(map(int, input().split(' ')))[::-1] # 거꾸로 탐색
print(s)
>>> [3, 8, 1, 5]
'Language > Python' 카테고리의 다른 글
python swea 2068 최대수 구하기 (0) | 2020.11.25 |
---|---|
python swea 2070 큰 놈, 작은 놈, 같은 놈 (0) | 2020.11.25 |
python swea 2072. 홀수만 더하기 (0) | 2020.11.24 |
Dictionary 딕셔너리 (0) | 2020.11.22 |
문자열 관련 함수 (0) | 2020.11.22 |