Language/Python
python 한 번에 여러 값 입력받기
olivia-com
2020. 11. 24. 23:00
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]