Programming/Python

[python]입력받기, 형변환, map, split

Nobb 2025. 9. 5. 10:59

* 입력함수  input()

a = input()			# '123'
a = int(input())		# 123
a,b,c = map(int, input())	# 1,2,3

 

 

* 형변환 함수

 - int()

 - float()

 - str()

 

 

* map()

 : 여러 개의 데이터를 한번에 함수 적용시키고 싶을 때 사용 (예: 다른 형태로 변환 등)

    - 주 대상: list, tuple 등의 sequence 대상

    - 사용:  map(변환함수 , 대상리스트)

    - ex)  a,b,c,d,e = map( int, input().split() )

a = int(input())	# 받은 문자열 통째로 int변환
b = map(int, input())	# 받은 문자열 하나씩 쪼개 int변환 (띄어쓰기 없는 경우)

a,b,c = map( int, input() )	# 123 -> a=1, b=2, c=3
a,b,c = map( int, input().split() )	# 1 2 3 -> a=1, b=2, c=3
arr = list(map( int, input().split() )	# 123 -> arr = [1,2,3]

 

 

* split()

  : 지정한 식별자 기준 문자열을 잘라서 리스트 만들어줌

     - 사용 :  대상문자열.split('식별자')