Python

[string] Python - format_map() 메서드 ★ - 문자열 안 지정 값의 형식 지정. (= 포맷맵)

3532
format_map() 예제

 

point = {'x':3,'y':-4}

print('{x} {y}'.format(**point))

 

결과값: 3 -4

 

format_map() 정의

 

문자열 안 지정 값을 형식 변경 후, 변경된 문자열 반환.

 


cf.

 

string.format(** mapping)

dict를 복사


string.format_map(mapping)

새 dict 생성. (※ dict 하위 클래스로 작업 시 유용.)

 

 

format_map() 구문

 

string.format_map(mapping)

 


[매개변수]

 

mapping

필수. dictionary 형태 취함. 

 

 

formap_map() 예제 

예제1 - 2개 경우

 

point = {'x':3,'y':-4}

print('{x} {y}'.format_map(point))

# 3 -4

 


예제2 - 3개 경우

 

point = {'x':3,'y':-4, 'z': 0}

print('{x} {y} {z}'.format_map(point))

# 3 -4 0

 


예제3 - 클래스 경우

 

 

 

class Hz(dict):

    def __missing__(self, key):

      return key


print('({x}, {y})'.format_map(Hz(x='4')))

print('({x}, {y})'.format_map(Hz(y='3')))

print('({x}, {y})'.format_map(Hz(x='4', y='3')))

 

결과값:

(4, y)

(x, 3)

(4, 3)



분류 제목
string Python - isdigit() 메서드 - 문자열이 digit 숫자뿐인지 체크. (= 이즈디지트)
string Python - isidentifier() 메서드 - 문자열이 유효한 식별자인지 체크 (= isidentif…
string Python - islower() 메서드 - 영문 문자열이 소문자뿐인지 체크. (= 이즈로우어)
string Python - isnumeric() 메서드 - 문자열이 numeric 숫자뿐인지 체크. (= 이즈뉴메릭)
string Python - isprintable() 메서드 - 문자열이 모두 인쇄 가능한지 체크. (= isprinta…
string Python - isspace() 메서드 - 문자열이 모두 공백인지 체크 (= isspace메서드 = 이즈스…
string Python - istitle() 메서드 ★ - 문자열 안 각 단어의 첫 글자만 대문자인지 체크. (= 이즈…
string Python - isupper() 메서드 - 영문 문자열이 대문자뿐인지 체크. (= isupper메서드 = …
string Python - join() 메서드 ★★ - 구분자 문자열로 연결/결합. (= join메서드 = 조인)
string Python - ljust() 메서드 - 반환된 문자열 길이의 왼쪽 정렬 (= ljust메서드 = 엘저스트메…
string Python - lower() 메서드 ★★ - 소문자로 변환 (= lower메서드 = 로우어메서드)
string Python - lstrip() 메서드 ★★ - 왼쪽 공백 제거. (= lstrip메서드 = 엘스트립메서드)
string Python - maketrans() 메서드 - 문자열 대체 매핑 테이블 생성 (= maketrans메서드 …
string Python - partition() 메서드 - 앞부터 지정 문자열 기준 3요소 갖는 Tuple 생성. (=…
string Python - replace() 메서드 ★ - 문자열 일부를 지정 문자열로 대체. (= replace메서드…
2/3
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인