파이썬[Python]: string - Formatter 클래스

string 모듈 - Formatter 클래스(class)


/// 설명

사용자가 일정한 형식을 가지고 있는 문자열을 생성할 수 있도록 합니다.

※ 형식
class string.Formatter

reference
https://docs.python.org/release/3.10.0/library/string.html

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from string import *
 
= Formatter()
 
print(a.format('one: {}, two: {}, three {}'123))  # one: 1, two: 2, three 3
print(a.format('one: {1}, two: {0}, three {2}''1''2''3'))  # one: 2, two: 1, three 3
 
test_str = 'name: {first}, {last}'
 
print(a.format('name: {first}, {last}', first='alan', last='Turing'))  # name: alan, Turing
 
test_dict = {'first''alan''last''Turing'}
print(a.format('name: {first}, {last}'**test_dict))  # name: alan, Turing
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수